home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / winsr173.zip / FRACTALS.C < prev    next >
C/C++ Source or Header  |  1992-07-05  |  87KB  |  3,057 lines

  1. /*
  2. FRACTALS.C, FRACTALP.C and CALCFRAC.C actually calculate the fractal
  3. images (well, SOMEBODY had to do it!).  The modules are set up so that
  4. all logic that is independent of any fractal-specific code is in
  5. CALCFRAC.C, the code that IS fractal-specific is in FRACTALS.C, and the
  6. struscture that ties (we hope!) everything together is in FRACTALP.C.
  7. Original author Tim Wegner, but just about ALL the authors have
  8. contributed SOME code to this routine at one time or another, or
  9. contributed to one of the many massive restructurings.
  10.  
  11. The Fractal-specific routines are divided into three categories:
  12.  
  13. 1. Routines that are called once-per-orbit to calculate the orbit
  14.    value. These have names like "XxxxFractal", and their function
  15.    pointers are stored in fractalspecific[fractype].orbitcalc. EVERY
  16.    new fractal type needs one of these. Return 0 to continue iterations,
  17.    1 if we're done. Results for integer fractals are left in 'lnew.x' and
  18.    'lnew.y', for floating point fractals in 'new.x' and 'new.y'.
  19.  
  20. 2. Routines that are called once per pixel to set various variables
  21.    prior to the orbit calculation. These have names like xxx_per_pixel
  22.    and are fairly generic - chances are one is right for your new type.
  23.    They are stored in fractalspecific[fractype].per_pixel.
  24.  
  25. 3. Routines that are called once per screen to set various variables.
  26.    These have names like XxxxSetup, and are stored in
  27.    fractalspecific[fractype].per_image.
  28.  
  29. 4. The main fractal routine. Usually this will be StandardFractal(),
  30.    but if you have written a stand-alone fractal routine independent
  31.    of the StandardFractal mechanisms, your routine name goes here,
  32.    stored in fractalspecific[fractype].calctype.per_image.
  33.  
  34. Adding a new fractal type should be simply a matter of adding an item
  35. to the 'fractalspecific' structure, writing (or re-using one of the existing)
  36. an appropriate setup, per_image, per_pixel, and orbit routines.
  37.  
  38. --------------------------------------------------------------------   */
  39.  
  40.  
  41. #include <stdio.h>
  42. #include <stdlib.h>
  43. #include <float.h>
  44. #include <limits.h>
  45. #include <string.h>
  46. #ifdef __TURBOC__
  47. #include <alloc.h>
  48. #else
  49. #include <malloc.h>
  50. #endif
  51. #include "fractint.h"
  52. #include "mpmath.h"
  53. #include "helpdefs.h"
  54. #include "fractype.h"
  55.  
  56. #define NEWTONDEGREELIMIT  100
  57.  
  58. extern struct complex  initorbit;
  59. extern struct lcomplex linitorbit;
  60. extern char useinitorbit;
  61. extern double fgLimit;
  62. extern int distest;
  63.  
  64. extern void (*ltrig0)();
  65. extern void (*ltrig1)();
  66. extern void (*ltrig2)();
  67. extern void (*ltrig3)();
  68. extern void (*dtrig0)();
  69. extern void (*dtrig1)();
  70. extern void (*dtrig2)();
  71. extern void (*dtrig3)();
  72.  
  73. /* -------------------------------------------------------------------- */
  74. /*   The following #defines allow the complex transcendental functions    */
  75. /*   in parser.c to be used here thus avoiding duplicated code.     */
  76. /* -------------------------------------------------------------------- */
  77.  
  78. #define CMPLXmod(z)      (sqr((z).x)+sqr((z).y))
  79. #define CMPLXconj(z)    ((z).y =  -((z).y))
  80. #define LCMPLXmod(z)       (lsqr((z).x)+lsqr((z).y))
  81. #define LCMPLXconj(z)    ((z).y =  -((z).y))
  82.  
  83.  
  84. #define LCMPLXtrig0(arg,out) Arg1->l = (arg); ltrig0(); (out)=Arg1->l
  85. #define LCMPLXtrig1(arg,out) Arg1->l = (arg); ltrig1(); (out)=Arg1->l
  86. #define LCMPLXtrig2(arg,out) Arg1->l = (arg); ltrig2(); (out)=Arg1->l
  87. #define LCMPLXtrig3(arg,out) Arg1->l = (arg); ltrig3(); (out)=Arg1->l
  88.  
  89. #define  CMPLXtrig0(arg,out) Arg1->d = (arg); dtrig0(); (out)=Arg1->d
  90. #define  CMPLXtrig1(arg,out) Arg1->d = (arg); dtrig1(); (out)=Arg1->d
  91. #define  CMPLXtrig2(arg,out) Arg1->d = (arg); dtrig2(); (out)=Arg1->d
  92. #define  CMPLXtrig3(arg,out) Arg1->d = (arg); dtrig3(); (out)=Arg1->d
  93.  
  94.  
  95. #define LCMPLXsin(arg,out)   Arg1->l = (arg); lStkSin();  (out) = Arg1->l
  96. #define LCMPLXcos(arg,out)   Arg1->l = (arg); lStkCos();  (out) = Arg1->l
  97. #define LCMPLXsinh(arg,out)  Arg1->l = (arg); lStkSinh(); (out) = Arg1->l
  98. #define LCMPLXcosh(arg,out)  Arg1->l = (arg); lStkCosh(); (out) = Arg1->l
  99. #define LCMPLXlog(arg,out)   Arg1->l = (arg); lStkLog();  (out) = Arg1->l
  100. #define LCMPLXexp(arg,out)   Arg1->l = (arg); lStkExp();  (out) = Arg1->l
  101. /*
  102. #define LCMPLXsqr(arg,out)   Arg1->l = (arg); lStkSqr();  (out) = Arg1->l
  103. */
  104. #define LCMPLXsqr(arg,out)   \
  105.    (out).x = lsqr((arg).x) - lsqr((arg).y);\
  106.    (out).y = multiply((arg).x, (arg).y, bitshiftless1)
  107. #define LCMPLXsqr_old(out)     \
  108.    (out).y = multiply(lold.x, lold.y, bitshiftless1);\
  109.    (out).x = ltempsqrx - ltempsqry\
  110.  
  111. #define LCMPLXpwr(arg1,arg2,out)    Arg2->l = (arg1); Arg1->l = (arg2);\
  112.      lStkPwr(); Arg1++; Arg2++; (out) = Arg2->l
  113. #define LCMPLXmult(arg1,arg2,out)    Arg2->l = (arg1); Arg1->l = (arg2);\
  114.      lStkMul(); Arg1++; Arg2++; (out) = Arg2->l
  115. #define LCMPLXadd(arg1,arg2,out)    \
  116.     (out).x = (arg1).x + (arg2).x; (out).y = (arg1).y + (arg2).y
  117. #define LCMPLXsub(arg1,arg2,out)    \
  118.     (out).x = (arg1).x - (arg2).x; (out).y = (arg1).y - (arg2).y
  119.  
  120. #define LCMPLXtimesreal(arg,real,out)    \
  121.     (out).x = multiply((arg).x,(real),bitshift);\
  122.     (out).y = multiply((arg).y,(real),bitshift)
  123.  
  124. #define LCMPLXrecip(arg,out)    \
  125. { long denom; denom = lsqr((arg).x) + lsqr((arg).y);\
  126. if(denom==0L) overflow=1; else {(out).x = divide((arg).x,denom,bitshift);\
  127. (out).y = -divide((arg).y,denom,bitshift);}}
  128.  
  129. #define CMPLXsin(arg,out)    Arg1->d = (arg); dStkSin();  (out) = Arg1->d
  130. #define CMPLXcos(arg,out)    Arg1->d = (arg); dStkCos();  (out) = Arg1->d
  131. #define CMPLXsinh(arg,out)   Arg1->d = (arg); dStkSinh(); (out) = Arg1->d
  132. #define CMPLXcosh(arg,out)   Arg1->d = (arg); dStkCosh(); (out) = Arg1->d
  133. #define CMPLXlog(arg,out)    Arg1->d = (arg); dStkLog();  (out) = Arg1->d
  134. #define CMPLXexp(arg,out)    FPUcplxexp(&(arg), &(out))
  135. /*
  136. #define CMPLXsqr(arg,out)    Arg1->d = (arg); dStkSqr();  (out) = Arg1->d
  137. */
  138. #define CMPLXsqr(arg,out)    \
  139.    (out).x = sqr((arg).x) - sqr((arg).y);\
  140.    (out).y = ((arg).x+(arg).x) * (arg).y
  141. #define CMPLXsqr_old(out)    \
  142.    (out).y = (old.x+old.x) * old.y;\
  143.    (out).x = tempsqrx - tempsqry
  144.  
  145. #define CMPLXpwr(arg1,arg2,out)   (out)= ComplexPower((arg1), (arg2))
  146. #define CMPLXmult1(arg1,arg2,out)    Arg2->d = (arg1); Arg1->d = (arg2);\
  147.      dStkMul(); Arg1++; Arg2++; (out) = Arg2->d
  148. #define CMPLXmult(arg1,arg2,out)  \
  149.     {\
  150.        CMPLX TmP;\
  151.        TmP.x = (arg1).x*(arg2).x - (arg1).y*(arg2).y;\
  152.        TmP.y = (arg1).x*(arg2).y + (arg1).y*(arg2).x;\
  153.        (out) = TmP;\
  154.      }
  155. #define CMPLXadd(arg1,arg2,out)    \
  156.     (out).x = (arg1).x + (arg2).x; (out).y = (arg1).y + (arg2).y
  157. #define CMPLXsub(arg1,arg2,out)    \
  158.     (out).x = (arg1).x - (arg2).x; (out).y = (arg1).y - (arg2).y
  159. #define CMPLXtimesreal(arg,real,out)   \
  160.     (out).x = (arg).x*(real);\
  161.     (out).y = (arg).y*(real)
  162.  
  163. #define CMPLXrecip(arg,out)    \
  164.    { double denom; denom = sqr((arg).x) + sqr((arg).y);\
  165.      if(denom==0.0) {(out).x = 1.0e10;(out).y = 1.0e10;}else\
  166.     { (out).x =  (arg).x/denom;\
  167.      (out).y = -(arg).y/denom;}}
  168.  
  169. extern int xshift, yshift;
  170. long Exp086(long);
  171. double fmod(double,double);
  172. extern int biomorph;
  173. extern int forcesymmetry;
  174. extern int symmetry;
  175. LCMPLX lcoefficient,lold,lnew,lparm, linit,ltmp,ltmp2,lparm2;
  176. long ltempsqrx,ltempsqry;
  177. extern int decomp[];
  178. extern double param[];
  179. extern int potflag;                   /* potential enabled? */
  180. extern double f_radius,f_xcenter,f_ycenter;    /* inversion radius, center */
  181. extern double xxmin,xxmax,yymin,yymax;           /* corners */
  182. extern int overflow;
  183. extern int integerfractal;    /* TRUE if fractal uses integer math */
  184.  
  185. int maxcolor;
  186. int root, degree,basin;
  187. double floatmin,floatmax;
  188. double roverd, d1overd, threshold;
  189. CMPLX tmp2;
  190. extern CMPLX init,tmp,old,new,saved,ComplexPower();
  191. CMPLX    staticroots[16]; /* roots array for degree 16 or less */
  192. CMPLX    *roots = staticroots;
  193. struct MPC    *MPCroots;
  194. extern int color, row, col;
  195. extern int invert;
  196. extern double far *dx0, far *dy0;
  197. extern double far *dx1, far *dy1;
  198. long FgHalf;
  199.  
  200. CMPLX one;
  201. CMPLX pwr;
  202. CMPLX Coefficient;
  203.  
  204. extern int    colors;             /* maximum colors available */
  205. extern int    inside;             /* "inside" color to use    */
  206. extern int    outside;            /* "outside" color to use   */
  207. extern int    finattract;
  208. extern int    fractype;            /* fractal type */
  209. extern int    debugflag;            /* for debugging purposes */
  210.  
  211. extern double    param[];        /* parameters */
  212. extern long    far *lx0, far *ly0;        /* X, Y points */
  213. extern long    far *lx1, far *ly1;        /* X, Y points */
  214. extern long    delx,dely;            /* X, Y increments */
  215. extern long    delmin;             /* min(max(dx),max(dy) */
  216. extern double    ddelmin;            /* min(max(dx),max(dy) */
  217. extern long    fudge;                /* fudge factor (2**n) */
  218. extern int    bitshift;            /* bit shift for fudge */
  219. int    bitshiftless1;            /* bit shift less 1 */
  220.  
  221. #ifndef sqr
  222. #define sqr(x) ((x)*(x))
  223. #endif
  224.  
  225. #ifndef lsqr
  226. #define lsqr(x) (multiply((x),(x),bitshift))
  227. #endif
  228.  
  229. #define modulus(z)     (sqr((z).x)+sqr((z).y))
  230. #define conjugate(pz)    ((pz)->y = 0.0 - (pz)->y)
  231. #define distance(z1,z2)  (sqr((z1).x-(z2).x)+sqr((z1).y-(z2).y))
  232. #define pMPsqr(z) (*pMPmul((z),(z)))
  233. #define MPdistance(z1,z2)  (*pMPadd(pMPsqr(*pMPsub((z1).x,(z2).x)),pMPsqr(*pMPsub((z1).y,(z2).y))))
  234.  
  235. double twopi = PI*2.0;
  236. static int c_exp;
  237.  
  238.  
  239. /* These are local but I don't want to pass them as parameters */
  240. CMPLX lambda;
  241. extern double magnitude, rqlim, rqlim2;
  242. CMPLX parm,parm2;
  243. CMPLX *floatparm;
  244. LCMPLX *longparm; /* used here and in jb.c */
  245. extern int (*calctype)();
  246. extern unsigned long lm;        /* magnitude limit (CALCMAND) */
  247.  
  248. /* -------------------------------------------------------------------- */
  249. /*        These variables are external for speed's sake only      */
  250. /* -------------------------------------------------------------------- */
  251.  
  252. double sinx,cosx,sinhx,coshx;
  253. double siny,cosy,sinhy,coshy;
  254. double tmpexp;
  255. double tempsqrx,tempsqry;
  256.  
  257. double foldxinitx,foldyinity,foldxinity,foldyinitx;
  258. long oldxinitx,oldyinity,oldxinity,oldyinitx;
  259. long longtmp;
  260. extern long lmagnitud, llimit, llimit2, l16triglim;
  261. extern periodicitycheck;
  262. extern char floatflag;
  263.  
  264. extern int StandardFractal();
  265. extern int NewtonFractal2(); /* Lee Crocker's Newton code */
  266.  
  267. /* these are in mpmath_c.c */
  268. extern int ComplexNewtonSetup(void);
  269. extern int ComplexNewton(void), ComplexBasin(void), MarksCplxMand(void);
  270. extern int MarksCplxMandperp(void);
  271.  
  272. /* these are in (I think) JB.C */
  273. extern int Std4dFractal(), JulibrotSetup(), jb_per_pixel();
  274.  
  275. extern int Lsystem();
  276. extern int lya_setup(void);
  277. extern int lyapunov(void);
  278.  
  279. /* temporary variables for trig use */
  280. long lcosx, lcoshx, lsinx, lsinhx;
  281. long lcosy, lcoshy, lsiny, lsinhy;
  282.  
  283. /*
  284. **  details of finite attractors (required for Magnet Fractals)
  285. **  (can also be used in "coloring in" the lakes of Julia types)
  286. */
  287. extern          int      attractors; /* number of finite attractors   */
  288. extern CMPLX  attr[];       /* finite attractor values (f.p) */
  289. extern LCMPLX lattr[];      /* finite attractor values (int) */
  290.  
  291. /*
  292. **  pre-calculated values for fractal types Magnet2M & Magnet2J
  293. */
  294. CMPLX    T_Cm1;          /* 3 * (floatparm - 1)            */
  295. CMPLX    T_Cm2;          /* 3 * (floatparm - 2)            */
  296. CMPLX    T_Cm1Cm2;     /* (floatparm - 1) * (floatparm - 2) */
  297.  
  298. void FloatPreCalcMagnet2() /* precalculation for Magnet2 (M & J) for speed */
  299.   {
  300.     T_Cm1.x = floatparm->x - 1.0;   T_Cm1.y = floatparm->y;
  301.     T_Cm2.x = floatparm->x - 2.0;   T_Cm2.y = floatparm->y;
  302.     T_Cm1Cm2.x = (T_Cm1.x * T_Cm2.x) - (T_Cm1.y * T_Cm2.y);
  303.     T_Cm1Cm2.y = (T_Cm1.x * T_Cm2.y) + (T_Cm1.y * T_Cm2.x);
  304.     T_Cm1.x += T_Cm1.x + T_Cm1.x;   T_Cm1.y += T_Cm1.y + T_Cm1.y;
  305.     T_Cm2.x += T_Cm2.x + T_Cm2.x;   T_Cm2.y += T_Cm2.y + T_Cm2.y;
  306.   }
  307.  
  308. /* -------------------------------------------------------------------- */
  309. /*        Stand-alone routines                                            */
  310. /* -------------------------------------------------------------------- */
  311.  
  312. extern int orbit2dfloat();
  313. extern int orbit2dlong();
  314. extern int kamtorusfloatorbit();
  315. extern int kamtoruslongorbit();
  316.  
  317. /* functions defined elswhere needed for fractalspecific */
  318. extern int hopalong2dfloatorbit();
  319. extern int martin2dfloatorbit();
  320. extern int orbit3dfloat();
  321. extern int orbit3dlong();
  322. extern int lorenz3dlongorbit();
  323. extern int orbit3dlongsetup();
  324. extern int lorenz3dfloatorbit();
  325. extern int lorenz3d1floatorbit();
  326. extern int lorenz3d3floatorbit();
  327. extern int lorenz3d4floatorbit();
  328. extern int orbit3dfloatsetup();
  329. extern int rosslerfloatorbit();
  330. extern int rosslerlongorbit();
  331. extern int henonfloatorbit();
  332. extern int henonlongorbit();
  333. extern int pickoverfloatorbit();
  334. extern int gingerbreadfloatorbit();
  335. extern int diffusion();
  336. extern int plasma();
  337. extern int test();
  338. extern int ifs();
  339. extern int Bifurcation(void);
  340. extern int BifurcVerhulst(void);
  341. extern int LongBifurcVerhulst(void);
  342. extern int BifurcLambda(void);
  343. extern int LongBifurcLambda(void);
  344. extern int BifurcAddSinPi(void);
  345. extern int LongBifurcAddSinPi(void);
  346. extern int BifurcSetSinPi(void);
  347. extern int LongBifurcSetSinPi(void);
  348. extern int BifurcStewart(void);
  349. extern int LongBifurcStewart(void);
  350. extern int popcorn(void);
  351.  
  352. /* -------------------------------------------------------------------- */
  353. /*        Bailout Routines Macros                                                 */
  354. /* -------------------------------------------------------------------- */
  355.  
  356. static int near floatbailout()
  357. {
  358.    if ( ( magnitude = ( tempsqrx=sqr(new.x) )
  359.             + ( tempsqry=sqr(new.y) ) ) >= rqlim ) return(1);
  360.    old = new;
  361.    return(0);
  362. }
  363.  
  364. /* longbailout() is equivalent to next */
  365. #define LONGBAILOUT()    \
  366.    ltempsqrx = lsqr(lnew.x); ltempsqry = lsqr(lnew.y);\
  367.    lmagnitud = ltempsqrx + ltempsqry;\
  368.    if (lmagnitud >= llimit || lmagnitud < 0 || labs(lnew.x) > llimit2\
  369.      || labs(lnew.y) > llimit2 || overflow) \
  370.            { overflow=0;return(1);}\
  371.    lold = lnew;
  372.  
  373. #define FLOATTRIGBAILOUT()  \
  374.    if (fabs(old.y) >= rqlim2) return(1);
  375.  
  376. #define LONGTRIGBAILOUT()  \
  377.    if(labs(lold.y) >= llimit2 || overflow) { overflow=0;return(1);}
  378.  
  379. #define LONGXYTRIGBAILOUT()  \
  380.    if(labs(lold.x) >= llimit2 || labs(lold.y) >= llimit2 || overflow)\
  381.     { overflow=0;return(1);}
  382.  
  383. #define FLOATXYTRIGBAILOUT()  \
  384.    if (fabs(old.x) >= rqlim2 || fabs(old.y) >= rqlim2) return(1);
  385.  
  386. #define FLOATHTRIGBAILOUT()  \
  387.    if (fabs(old.x) >= rqlim2) return(1);
  388.  
  389. #define LONGHTRIGBAILOUT()  \
  390.    if(labs(lold.x) >= llimit2 || overflow) { overflow=0;return(1);}
  391.  
  392. #define TRIG16CHECK(X)    \
  393.       if(labs((X)) > l16triglim || overflow) { overflow=0;return(1);}
  394.  
  395. #define FLOATEXPBAILOUT()  \
  396.    if (fabs(old.y) >= 1.0e8) return(1);\
  397.    if (fabs(old.x) >= 6.4e2) return(1);
  398.  
  399. #define LONGEXPBAILOUT()  \
  400.    if (labs(lold.y) >= (1000L<<bitshift)) return(1);\
  401.    if (labs(lold.x) >=      (8L<<bitshift)) return(1);
  402.  
  403. #if 0
  404. /* this define uses usual trig instead of fast trig */
  405. #define FPUsincos(px,psinx,pcosx) \
  406.    *(psinx) = sin(*(px));\
  407.    *(pcosx) = cos(*(px));
  408.  
  409. #define FPUsinhcosh(px,psinhx,pcoshx) \
  410.    *(psinhx) = sinh(*(px));\
  411.    *(pcoshx) = cosh(*(px));
  412. #endif
  413.  
  414. #define LTRIGARG(X)    \
  415.    if(labs((X)) > l16triglim)\
  416.    {\
  417.       double tmp;\
  418.       tmp = (X);\
  419.       tmp /= fudge;\
  420.       tmp = fmod(tmp,twopi);\
  421.       tmp *= fudge;\
  422.       (X) = tmp;\
  423.    }\
  424.  
  425. /* -------------------------------------------------------------------- */
  426. /*        Fractal (once per iteration) routines            */
  427. /* -------------------------------------------------------------------- */
  428. static double xt, yt, t2;
  429.  
  430. /* Raise complex number (base) to the (exp) power, storing the result
  431. ** in complex (result).
  432. */
  433. void cpower(CMPLX *base, int exp, CMPLX *result)
  434. {
  435.     xt = base->x;   yt = base->y;
  436.  
  437.     if (exp & 1)
  438.     {
  439.        result->x = xt;
  440.        result->y = yt;
  441.     }
  442.     else
  443.     {
  444.        result->x = 1.0;
  445.        result->y = 0.0;
  446.     }
  447.  
  448.     exp >>= 1;
  449.     while (exp)
  450.     {
  451.     t2 = xt * xt - yt * yt;
  452.     yt = 2 * xt * yt;
  453.     xt = t2;
  454.  
  455.     if (exp & 1)
  456.     {
  457.         t2 = xt * result->x - yt * result->y;
  458.         result->y = result->y * xt + yt * result->x;
  459.         result->x = t2;
  460.     }
  461.     exp >>= 1;
  462.     }
  463. }
  464. /* long version */
  465. static long lxt, lyt, lt2;
  466.  
  467. lcpower(LCMPLX *base, int exp, LCMPLX *result, int bitshift)
  468. {
  469.     static long maxarg;
  470.     maxarg = 64L<<bitshift;
  471.  
  472.     overflow = 0;
  473.     lxt = base->x;   lyt = base->y;
  474.  
  475.     if (exp & 1)
  476.     {
  477.        result->x = lxt;
  478.        result->y = lyt;
  479.     }
  480.     else
  481.     {
  482.        result->x = 1L<<bitshift;
  483.        result->y = 0L;
  484.     }
  485.  
  486.     exp >>= 1;
  487.     while (exp)
  488.     {
  489.     /*
  490.     if(labs(lxt) >= maxarg || labs(lyt) >= maxarg)
  491.        return(-1);
  492.     */
  493.     lt2 = multiply(lxt, lxt, bitshift) - multiply(lyt,lyt,bitshift);
  494.     lyt = multiply(lxt,lyt,bitshiftless1);
  495.     if(overflow)
  496.        return(overflow);
  497.     lxt = lt2;
  498.  
  499.     if (exp & 1)
  500.     {
  501.         lt2 = multiply(lxt,result->x, bitshift) - multiply(lyt,result->y,bitshift);
  502.         result->y = multiply(result->y,lxt,bitshift) + multiply(lyt,result->x,bitshift);
  503.         result->x = lt2;
  504.     }
  505.     exp >>= 1;
  506.     }
  507.     if(result->x == 0 && result->y == 0)
  508.        overflow = 1;
  509.     return(overflow);
  510. }
  511. #if 0
  512. z_to_the_z(CMPLX *z, CMPLX *out)
  513. {
  514.     static CMPLX tmp1,tmp2;
  515.     /* raises complex z to the z power */
  516.     int errno_xxx;
  517.     errno_xxx = 0;
  518.  
  519.     if(fabs(z->x) < DBL_EPSILON) return(-1);
  520.  
  521.     /* log(x + iy) = 1/2(log(x*x + y*y) + i(arc_tan(y/x)) */
  522.     tmp1.x = .5*log(sqr(z->x)+sqr(z->y));
  523.  
  524.     /* the fabs in next line added to prevent discontinuity in image */
  525.     tmp1.y = atan(fabs(z->y/z->x));
  526.  
  527.     /* log(z)*z */
  528.     tmp2.x = tmp1.x * z->x - tmp1.y * z->y;
  529.     tmp2.y = tmp1.x * z->y + tmp1.y * z->x;
  530.  
  531.     /* z*z = e**(log(z)*z) */
  532.     /* e**(x + iy) =  e**x * (cos(y) + isin(y)) */
  533.  
  534.     tmpexp = exp(tmp2.x);
  535.  
  536.     FPUsincos(&tmp2.y,&siny,&cosy);
  537.     out->x = tmpexp*cosy;
  538.     out->y = tmpexp*siny;
  539.     return(errno_xxx);
  540. }
  541. #endif
  542. /* Distance of complex z from unit circle */
  543. #define DIST1(z) (((z).x-1.0)*((z).x-1.0)+((z).y)*((z).y))
  544. #define LDIST1(z) (lsqr((((z).x)-fudge)) + lsqr(((z).y)))
  545.  
  546. #ifdef NEWTON
  547. complex_mult(CMPLX arg1,CMPLX arg2,CMPLX *pz);
  548. complex_div(CMPLX arg1,CMPLX arg2,CMPLX *pz);
  549.  
  550. int NewtonFractal()
  551. {
  552.     static char start=1;
  553.     if(start)
  554.     {
  555.        start = 0;
  556.     }
  557.     cpower(&old, degree-1, &tmp);
  558.     complex_mult(tmp, old, &new);
  559.  
  560.     if (DIST1(new) < threshold)
  561.     {
  562.        if(fractype==NEWTBASIN)
  563.        {
  564.       int tmpcolor;
  565.       int i;
  566.       tmpcolor = -1;
  567.       /* this code determines which degree-th root of root the
  568.          Newton formula converges to. The roots of a 1 are
  569.          distributed on a circle of radius 1 about the origin. */
  570.       for(i=0;i<degree;i++)
  571.          /* color in alternating shades with iteration according to
  572.         which root of 1 it converged to */
  573.           if(distance(roots[i],old) < threshold)
  574.           {
  575.            /*    tmpcolor = 1+(i&7)+((color&1)<<3); */
  576.            tmpcolor = 1+i;
  577.            break;
  578.           }
  579.        if(tmpcolor == -1)
  580.           color = maxcolor;
  581.        else
  582.           color = tmpcolor;
  583.        }
  584.        return(1);
  585.     }
  586.     new.x = d1overd * new.x + roverd;
  587.     new.y *= d1overd;
  588.  
  589.     /* Watch for divide underflow */
  590.     if ((t2 = tmp.x * tmp.x + tmp.y * tmp.y) < FLT_MIN)
  591.       return(1);
  592.     else
  593.     {
  594.     t2 = 1.0 / t2;
  595.     old.x = t2 * (new.x * tmp.x + new.y * tmp.y);
  596.     old.y = t2 * (new.y * tmp.x - new.x * tmp.y);
  597.     }
  598.     return(0);
  599. }
  600.  
  601.  
  602. complex_mult(arg1,arg2,pz)
  603. CMPLX arg1,arg2,*pz;
  604. {
  605.    pz->x = arg1.x*arg2.x - arg1.y*arg2.y;
  606.    pz->y = arg1.x*arg2.y+arg1.y*arg2.x;
  607.    return(0);
  608. }
  609.  
  610. complex_div(numerator,denominator,pout)
  611. CMPLX numerator,denominator,*pout;
  612. {
  613.    double mod;
  614.    if((mod = modulus(denominator)) < FLT_MIN)
  615.       return(1);
  616.    conjugate(&denominator);
  617.    complex_mult(numerator,denominator,pout);
  618.    pout->x = pout->x/mod;
  619.    pout->y = pout->y/mod;
  620.    return(0);
  621. }
  622.  
  623.  
  624. lcomplex_mult(arg1,arg2,pz,bitshift)
  625. LCMPLX arg1,arg2,*pz;
  626. int bitshift;
  627. {
  628.    overflow = 0;
  629.    pz->x = multiply(arg1.x,arg2.x,bitshift) - multiply(arg1.y,arg2.y,bitshift);
  630.    pz->y = multiply(arg1.x,arg2.y,bitshift) + multiply(arg1.y,arg2.x,bitshift);
  631.    return(overflow);
  632. }
  633.  
  634. #endif
  635.  
  636. #define MPCmod(m) (*pMPadd(*pMPmul((m).x, (m).x), *pMPmul((m).y, (m).y)))
  637. struct MPC mpcold, mpcnew, mpctmp, mpctmp1;
  638. struct MP mproverd, mpd1overd, mpthreshold,sqrmpthreshold;
  639. struct MP mpt2;
  640. struct MP mpone;
  641. extern struct MPC MPCone;
  642. extern int MPOverflow;
  643. int MPCNewtonFractal()
  644. {
  645.     MPOverflow = 0;
  646.     mpctmp   = MPCpow(mpcold,degree-1);
  647.  
  648.     mpcnew.x = *pMPsub(*pMPmul(mpctmp.x,mpcold.x),*pMPmul(mpctmp.y,mpcold.y));
  649.     mpcnew.y = *pMPadd(*pMPmul(mpctmp.x,mpcold.y),*pMPmul(mpctmp.y,mpcold.x));
  650.  
  651.     mpctmp1.x = *pMPsub(mpcnew.x, MPCone.x);
  652.     mpctmp1.y = *pMPsub(mpcnew.y, MPCone.y);
  653.  
  654.     if(pMPcmp(MPCmod(mpctmp1),mpthreshold)< 0)
  655.     {
  656.       if(fractype==MPNEWTBASIN)
  657.       {
  658.      int tmpcolor;
  659.      int i;
  660.      tmpcolor = -1;
  661.      for(i=0;i<degree;i++)
  662.          if(pMPcmp(MPdistance(MPCroots[i],mpcold),mpthreshold) < 0)
  663.          {
  664.         if(basin==2)
  665.            tmpcolor = 1+(i&7) + ((color&1)<<3);
  666.         else
  667.            tmpcolor = 1+i;
  668.             break;
  669.          }
  670.       if(tmpcolor == -1)
  671.          color = maxcolor;
  672.       else
  673.          color = tmpcolor;
  674.       }
  675.        return(1);
  676.     }
  677.  
  678.     mpcnew.x = *pMPadd(*pMPmul(mpd1overd,mpcnew.x),mproverd);
  679.     mpcnew.y = *pMPmul(mpcnew.y,mpd1overd);
  680.  
  681.     mpt2 = MPCmod(mpctmp);
  682.     mpt2 = *pMPdiv(mpone,mpt2);
  683.  
  684.     mpcold.x = *pMPmul(mpt2,(*pMPadd(*pMPmul(mpcnew.x,mpctmp.x),*pMPmul(mpcnew.y,mpctmp.y))));
  685.     mpcold.y = *pMPmul(mpt2,(*pMPsub(*pMPmul(mpcnew.y,mpctmp.x),*pMPmul(mpcnew.x,mpctmp.y))));
  686.  
  687.     new.x = *pMP2d(mpcold.x);
  688.     new.y = *pMP2d(mpcold.y);
  689.     return(MPOverflow);
  690. }
  691.  
  692.  
  693. Barnsley1Fractal()
  694. {
  695.    /* Barnsley's Mandelbrot type M1 from "Fractals
  696.    Everywhere" by Michael Barnsley, p. 322 */
  697.  
  698.    /* calculate intermediate products */
  699.    oldxinitx   = multiply(lold.x, longparm->x, bitshift);
  700.    oldyinity   = multiply(lold.y, longparm->y, bitshift);
  701.    oldxinity   = multiply(lold.x, longparm->y, bitshift);
  702.    oldyinitx   = multiply(lold.y, longparm->x, bitshift);
  703.    /* orbit calculation */
  704.    if(lold.x >= 0)
  705.    {
  706.       lnew.x = (oldxinitx - longparm->x - oldyinity);
  707.       lnew.y = (oldyinitx - longparm->y + oldxinity);
  708.    }
  709.    else
  710.    {
  711.       lnew.x = (oldxinitx + longparm->x - oldyinity);
  712.       lnew.y = (oldyinitx + longparm->y + oldxinity);
  713.    }
  714.    return(longbailout());
  715. }
  716.  
  717. Barnsley1FPFractal()
  718. {
  719.    /* Barnsley's Mandelbrot type M1 from "Fractals
  720.    Everywhere" by Michael Barnsley, p. 322 */
  721.    /* note that fast >= 287 equiv in fracsuba.asm must be kept in step */
  722.  
  723.    /* calculate intermediate products */
  724.    foldxinitx = old.x * floatparm->x;
  725.    foldyinity = old.y * floatparm->y;
  726.    foldxinity = old.x * floatparm->y;
  727.    foldyinitx = old.y * floatparm->x;
  728.    /* orbit calculation */
  729.    if(old.x >= 0)
  730.    {
  731.       new.x = (foldxinitx - floatparm->x - foldyinity);
  732.       new.y = (foldyinitx - floatparm->y + foldxinity);
  733.    }
  734.    else
  735.    {
  736.       new.x = (foldxinitx + floatparm->x - foldyinity);
  737.       new.y = (foldyinitx + floatparm->y + foldxinity);
  738.    }
  739.    return(floatbailout());
  740. }
  741.  
  742. Barnsley2Fractal()
  743. {
  744.    /* An unnamed Mandelbrot/Julia function from "Fractals
  745.    Everywhere" by Michael Barnsley, p. 331, example 4.2 */
  746.    /* note that fast >= 287 equiv in fracsuba.asm must be kept in step */
  747.  
  748.    /* calculate intermediate products */
  749.    oldxinitx   = multiply(lold.x, longparm->x, bitshift);
  750.    oldyinity   = multiply(lold.y, longparm->y, bitshift);
  751.    oldxinity   = multiply(lold.x, longparm->y, bitshift);
  752.    oldyinitx   = multiply(lold.y, longparm->x, bitshift);
  753.  
  754.    /* orbit calculation */
  755.    if(oldxinity + oldyinitx >= 0)
  756.    {
  757.       lnew.x = oldxinitx - longparm->x - oldyinity;
  758.       lnew.y = oldyinitx - longparm->y + oldxinity;
  759.    }
  760.    else
  761.    {
  762.       lnew.x = oldxinitx + longparm->x - oldyinity;
  763.       lnew.y = oldyinitx + longparm->y + oldxinity;
  764.    }
  765.    return(longbailout());
  766. }
  767.  
  768. Barnsley2FPFractal()
  769. {
  770.    /* An unnamed Mandelbrot/Julia function from "Fractals
  771.    Everywhere" by Michael Barnsley, p. 331, example 4.2 */
  772.  
  773.    /* calculate intermediate products */
  774.    foldxinitx = old.x * floatparm->x;
  775.    foldyinity = old.y * floatparm->y;
  776.    foldxinity = old.x * floatparm->y;
  777.    foldyinitx = old.y * floatparm->x;
  778.  
  779.    /* orbit calculation */
  780.    if(foldxinity + foldyinitx >= 0)
  781.    {
  782.       new.x = foldxinitx - floatparm->x - foldyinity;
  783.       new.y = foldyinitx - floatparm->y + foldxinity;
  784.    }
  785.    else
  786.    {
  787.       new.x = foldxinitx + floatparm->x - foldyinity;
  788.       new.y = foldyinitx + floatparm->y + foldxinity;
  789.    }
  790.    return(floatbailout());
  791. }
  792.  
  793. JuliaFractal()
  794. {
  795.    /* used for C prototype of fast integer math routines for classic
  796.       Mandelbrot and Julia */
  797.    lnew.x  = ltempsqrx - ltempsqry + longparm->x;
  798.    lnew.y = multiply(lold.x, lold.y, bitshiftless1) + longparm->y;
  799.    return(longbailout());
  800. }
  801.  
  802. JuliafpFractal()
  803. {
  804.    /* floating point version of classical Mandelbrot/Julia */
  805.    /* note that fast >= 287 equiv in fracsuba.asm must be kept in step */
  806.    new.x = tempsqrx - tempsqry + floatparm->x;
  807.    new.y = 2.0 * old.x * old.y + floatparm->y;
  808.    return(floatbailout());
  809. }
  810.  
  811. static double f(double x, double y)
  812. {
  813.    return(x - x*y);
  814. }
  815.  
  816. static double g(double x, double y)
  817. {
  818.    return(-y + x*y);
  819. }
  820.  
  821. LambdaFPFractal()
  822. {
  823.    /* variation of classical Mandelbrot/Julia */
  824.    /* note that fast >= 287 equiv in fracsuba.asm must be kept in step */
  825.  
  826.    tempsqrx = old.x - tempsqrx + tempsqry;
  827.    tempsqry = -(old.y * old.x);
  828.    tempsqry += tempsqry + old.y;
  829.  
  830.    new.x = floatparm->x * tempsqrx - floatparm->y * tempsqry;
  831.    new.y = floatparm->x * tempsqry + floatparm->y * tempsqrx;
  832.    return(floatbailout());
  833. }
  834.  
  835. LambdaFractal()
  836. {
  837.    /* variation of classical Mandelbrot/Julia */
  838.  
  839.    /* in complex math) temp = Z * (1-Z) */
  840.    ltempsqrx = lold.x - ltempsqrx + ltempsqry;
  841.    ltempsqry = lold.y
  842.          - multiply(lold.y, lold.x, bitshiftless1);
  843.    /* (in complex math) Z = Lambda * Z */
  844.    lnew.x = multiply(longparm->x, ltempsqrx, bitshift)
  845.     - multiply(longparm->y, ltempsqry, bitshift);
  846.    lnew.y = multiply(longparm->x, ltempsqry, bitshift)
  847.     + multiply(longparm->y, ltempsqrx, bitshift);
  848.    return(longbailout());
  849. }
  850.  
  851. SierpinskiFractal()
  852. {
  853.    /* following code translated from basic - see "Fractals
  854.    Everywhere" by Michael Barnsley, p. 251, Program 7.1.1 */
  855.    lnew.x = (lold.x << 1);        /* new.x = 2 * old.x  */
  856.    lnew.y = (lold.y << 1);        /* new.y = 2 * old.y  */
  857.    if(lold.y > ltmp.y)    /* if old.y > .5 */
  858.       lnew.y = lnew.y - ltmp.x; /* new.y = 2 * old.y - 1 */
  859.    else if(lold.x > ltmp.y)    /* if old.x > .5 */
  860.       lnew.x = lnew.x - ltmp.x; /* new.x = 2 * old.x - 1 */
  861.    /* end barnsley code */
  862.    return(longbailout());
  863. }
  864.  
  865. SierpinskiFPFractal()
  866. {
  867.    /* following code translated from basic - see "Fractals
  868.    Everywhere" by Michael Barnsley, p. 251, Program 7.1.1 */
  869.  
  870.    new.x = old.x + old.x;
  871.    new.y = old.y + old.y;
  872.    if(old.y > .5)
  873.       new.y = new.y - 1;
  874.    else if (old.x > .5)
  875.       new.x = new.x - 1;
  876.  
  877.    /* end barnsley code */
  878.    return(floatbailout());
  879. }
  880.  
  881. LambdaexponentFractal()
  882. {
  883.    /* found this in  "Science of Fractal Images" */
  884.    FLOATEXPBAILOUT();
  885.    FPUsincos  (&old.y,&siny,&cosy);
  886.  
  887.    if (old.x >= rqlim && cosy >= 0.0) return(1);
  888.    tmpexp = exp(old.x);
  889.    tmp.x = tmpexp*cosy;
  890.    tmp.y = tmpexp*siny;
  891.  
  892.    /*multiply by lamda */
  893.    new.x = floatparm->x*tmp.x - floatparm->y*tmp.y;
  894.    new.y = floatparm->y*tmp.x + floatparm->x*tmp.y;
  895.    old = new;
  896.    return(0);
  897. }
  898.  
  899. LongLambdaexponentFractal()
  900. {
  901.    /* found this in  "Science of Fractal Images" */
  902.    LONGEXPBAILOUT();
  903.  
  904.    SinCos086  (lold.y, &lsiny,    &lcosy);
  905.  
  906.    if (lold.x >= llimit && lcosy >= 0L) return(1);
  907.    longtmp = Exp086(lold.x);
  908.  
  909.    ltmp.x = multiply(longtmp,       lcosy,   bitshift);
  910.    ltmp.y = multiply(longtmp,       lsiny,   bitshift);
  911.  
  912.    lnew.x  = multiply(longparm->x, ltmp.x, bitshift)
  913.        - multiply(longparm->y, ltmp.y, bitshift);
  914.    lnew.y  = multiply(longparm->x, ltmp.y, bitshift)
  915.        + multiply(longparm->y, ltmp.x, bitshift);
  916.    lold = lnew;
  917.    return(0);
  918. }
  919.  
  920. FloatTrigPlusExponentFractal()
  921. {
  922.    /* another Scientific American biomorph type */
  923.    /* z(n+1) = e**z(n) + trig(z(n)) + C */
  924.  
  925.    if (fabs(old.x) >= 6.4e2) return(1); /* DOMAIN errors */
  926.    tmpexp = exp(old.x);
  927.    FPUsincos  (&old.y,&siny,&cosy);
  928.    CMPLXtrig0(old,new);
  929.  
  930.    /*new =   trig(old) + e**old + C  */
  931.    new.x += tmpexp*cosy + floatparm->x;
  932.    new.y += tmpexp*siny + floatparm->y;
  933.    return(floatbailout());
  934. }
  935.  
  936.  
  937. LongTrigPlusExponentFractal()
  938. {
  939.    /* calculate exp(z) */
  940.  
  941.    /* domain check for fast transcendental functions */
  942.    TRIG16CHECK(lold.x);
  943.    TRIG16CHECK(lold.y);
  944.  
  945.    longtmp = Exp086(lold.x);
  946.    SinCos086  (lold.y, &lsiny,    &lcosy);
  947.    LCMPLXtrig0(lold,lnew);
  948.    lnew.x += multiply(longtmp,      lcosy,   bitshift) + longparm->x;
  949.    lnew.y += multiply(longtmp,      lsiny,   bitshift) + longparm->y;
  950.    return(longbailout());
  951. }
  952.  
  953. MarksLambdaFractal()
  954. {
  955.    /* Mark Peterson's variation of "lambda" function */
  956.  
  957.    /* Z1 = (C^(exp-1) * Z**2) + C */
  958.    ltmp.x = ltempsqrx - ltempsqry;
  959.    ltmp.y = multiply(lold.x ,lold.y ,bitshiftless1);
  960.  
  961.    lnew.x = multiply(lcoefficient.x, ltmp.x, bitshift)
  962.     - multiply(lcoefficient.y, ltmp.y, bitshift) + longparm->x;
  963.    lnew.y = multiply(lcoefficient.x, ltmp.y, bitshift)
  964.     + multiply(lcoefficient.y, ltmp.x, bitshift) + longparm->y;
  965.  
  966.    return(longbailout());
  967. }
  968.  
  969.  
  970. long XXOne, FgOne, FgTwo;
  971.  
  972. UnityFractal()
  973. {
  974.    /* brought to you by Mark Peterson - you won't find this in any fractal
  975.       books unless they saw it here first - Mark invented it! */
  976.    XXOne = multiply(lold.x, lold.x, bitshift) + multiply(lold.y, lold.y, bitshift);
  977.    if((XXOne > FgTwo) || (labs(XXOne - FgOne) < delmin))
  978.       return(1);
  979.    lold.y = multiply(FgTwo - XXOne, lold.x, bitshift);
  980.    lold.x = multiply(FgTwo - XXOne, lold.y, bitshift);
  981.    lnew=lold;  /* TW added this line */
  982.    return(0);
  983. }
  984.  
  985. #define XXOne new.x
  986.  
  987. UnityfpFractal()
  988. {
  989.    /* brought to you by Mark Peterson - you won't find this in any fractal
  990.       books unless they saw it here first - Mark invented it! */
  991.  
  992.    XXOne = sqr(old.x) + sqr(old.y);
  993.    if((XXOne > 2.0) || (fabs(XXOne - 1.0) < ddelmin))
  994.       return(1);
  995.    old.y = (2.0 - XXOne)* old.x;
  996.    old.x = (2.0 - XXOne)* old.y;
  997.    new=old;  /* TW added this line */
  998.    return(0);
  999. }
  1000.  
  1001. #undef XXOne
  1002.  
  1003. Mandel4Fractal()
  1004. {
  1005.    /* By writing this code, Bert has left behind the excuse "don't
  1006.       know what a fractal is, just know how to make'em go fast".
  1007.       Bert is hereby declared a bonafide fractal expert! Supposedly
  1008.       this routine calculates the Mandelbrot/Julia set based on the
  1009.       polynomial z**4 + lambda, but I wouldn't know -- can't follow
  1010.       all that integer math speedup stuff - Tim */
  1011.  
  1012.    /* first, compute (x + iy)**2 */
  1013.    lnew.x  = ltempsqrx - ltempsqry;
  1014.    lnew.y = multiply(lold.x, lold.y, bitshiftless1);
  1015.    if (longbailout()) return(1);
  1016.  
  1017.    /* then, compute ((x + iy)**2)**2 + lambda */
  1018.    lnew.x  = ltempsqrx - ltempsqry + longparm->x;
  1019.    lnew.y = multiply(lold.x, lold.y, bitshiftless1) + longparm->y;
  1020.    return(longbailout());
  1021. }
  1022.  
  1023. floatZtozPluszpwrFractal()
  1024. {
  1025.    cpower(&old,(int)param[2],&new);
  1026.    old = ComplexPower(old,old);
  1027.    new.x = new.x + old.x +floatparm->x;
  1028.    new.y = new.y + old.y +floatparm->y;
  1029.    return(floatbailout());
  1030. }
  1031.  
  1032. longZpowerFractal()
  1033. {
  1034.    if(lcpower(&lold,c_exp,&lnew,bitshift))
  1035.       lnew.x = lnew.y = 8L<<bitshift;
  1036.    lnew.x += longparm->x;
  1037.    lnew.y += longparm->y;
  1038.    return(longbailout());
  1039. }
  1040.  
  1041. longCmplxZpowerFractal()
  1042. {
  1043.    struct complex x, y;
  1044.  
  1045.    x.x = (double)lold.x / fudge;
  1046.    x.y = (double)lold.y / fudge;
  1047.    y.x = (double)lparm2.x / fudge;
  1048.    y.y = (double)lparm2.y / fudge;
  1049.    x = ComplexPower(x, y);
  1050.    if(fabs(x.x) < fgLimit && fabs(x.y) < fgLimit) {
  1051.       lnew.x = (long)(x.x * fudge);
  1052.       lnew.y = (long)(x.y * fudge);
  1053.    }
  1054.    else
  1055.       overflow = 1;
  1056.    lnew.x += longparm->x;
  1057.    lnew.y += longparm->y;
  1058.    return(longbailout());
  1059. }
  1060.  
  1061. floatZpowerFractal()
  1062. {
  1063.    cpower(&old,c_exp,&new);
  1064.    new.x += floatparm->x;
  1065.    new.y += floatparm->y;
  1066.    return(floatbailout());
  1067. }
  1068.  
  1069. floatCmplxZpowerFractal()
  1070. {
  1071.    new = ComplexPower(old, parm2);
  1072.    new.x += floatparm->x;
  1073.    new.y += floatparm->y;
  1074.    return(floatbailout());
  1075. }
  1076.  
  1077. Barnsley3Fractal()
  1078. {
  1079.    /* An unnamed Mandelbrot/Julia function from "Fractals
  1080.    Everywhere" by Michael Barnsley, p. 292, example 4.1 */
  1081.  
  1082.    /* calculate intermediate products */
  1083.    oldxinitx   = multiply(lold.x, lold.x, bitshift);
  1084.    oldyinity   = multiply(lold.y, lold.y, bitshift);
  1085.    oldxinity   = multiply(lold.x, lold.y, bitshift);
  1086.  
  1087.    /* orbit calculation */
  1088.    if(lold.x > 0)
  1089.    {
  1090.       lnew.x = oldxinitx   - oldyinity - fudge;
  1091.       lnew.y = oldxinity << 1;
  1092.    }
  1093.    else
  1094.    {
  1095.       lnew.x = oldxinitx - oldyinity - fudge
  1096.        + multiply(longparm->x,lold.x,bitshift);
  1097.       lnew.y = oldxinity <<1;
  1098.  
  1099.       /* This term added by Tim Wegner to make dependent on the
  1100.      imaginary part of the parameter. (Otherwise Mandelbrot
  1101.      is uninteresting. */
  1102.       lnew.y += multiply(longparm->y,lold.x,bitshift);
  1103.    }
  1104.    return(longbailout());
  1105. }
  1106.  
  1107. Barnsley3FPFractal()
  1108. {
  1109.    /* An unnamed Mandelbrot/Julia function from "Fractals
  1110.    Everywhere" by Michael Barnsley, p. 292, example 4.1 */
  1111.  
  1112.  
  1113.    /* calculate intermediate products */
  1114.    foldxinitx  = old.x * old.x;
  1115.    foldyinity  = old.y * old.y;
  1116.    foldxinity  = old.x * old.y;
  1117.  
  1118.    /* orbit calculation */
  1119.    if(old.x > 0)
  1120.    {
  1121.       new.x = foldxinitx - foldyinity - 1.0;
  1122.       new.y = foldxinity * 2;
  1123.    }
  1124.    else
  1125.    {
  1126.       new.x = foldxinitx - foldyinity -1.0 + floatparm->x * old.x;
  1127.       new.y = foldxinity * 2;
  1128.  
  1129.       /* This term added by Tim Wegner to make dependent on the
  1130.      imaginary part of the parameter. (Otherwise Mandelbrot
  1131.      is uninteresting. */
  1132.       new.y += floatparm->y * old.x;
  1133.    }
  1134.    return(floatbailout());
  1135. }
  1136.  
  1137. TrigPlusZsquaredFractal()
  1138. {
  1139.    /* From Scientific American, July 1989 */
  1140.    /* A Biomorph              */
  1141.    /* z(n+1) = trig(z(n))+z(n)**2+C      */
  1142.    LCMPLXtrig0(lold,lnew);
  1143.    lnew.x += ltempsqrx - ltempsqry + longparm->x;
  1144.    lnew.y += multiply(lold.x, lold.y, bitshiftless1) + longparm->y;
  1145.    return(longbailout());
  1146. }
  1147.  
  1148. TrigPlusZsquaredfpFractal()
  1149. {
  1150.    /* From Scientific American, July 1989 */
  1151.    /* A Biomorph              */
  1152.    /* z(n+1) = trig(z(n))+z(n)**2+C      */
  1153.  
  1154.    CMPLXtrig0(old,new);
  1155.    new.x += tempsqrx - tempsqry + floatparm->x;
  1156.    new.y += 2.0 * old.x * old.y + floatparm->y;
  1157.    return(floatbailout());
  1158. }
  1159.  
  1160. Richard8fpFractal()
  1161. {
  1162.    /*  Richard8 {c = z = pixel: z=sin(z)+sin(pixel),|z|<=50} */
  1163.    CMPLXtrig0(old,new);
  1164. /*   CMPLXtrig1(*floatparm,tmp); */
  1165.    new.x += tmp.x;
  1166.    new.y += tmp.y;
  1167.    return(floatbailout());
  1168. }
  1169.  
  1170. Richard8Fractal()
  1171. {
  1172.    /*  Richard8 {c = z = pixel: z=sin(z)+sin(pixel),|z|<=50} */
  1173.    LCMPLXtrig0(lold,lnew);
  1174. /*   LCMPLXtrig1(*longparm,ltmp); */
  1175.    lnew.x += ltmp.x;
  1176.    lnew.y += ltmp.y;
  1177.    return(longbailout());
  1178. }
  1179.  
  1180. PopcornFractal()
  1181. {
  1182.    extern int row;
  1183.    tmp = old;
  1184.    tmp.x *= 3.0;
  1185.    tmp.y *= 3.0;
  1186.    FPUsincos(&tmp.x,&sinx,&cosx);
  1187.    FPUsincos(&tmp.y,&siny,&cosy);
  1188.    tmp.x = sinx/cosx + old.x;
  1189.    tmp.y = siny/cosy + old.y;
  1190.    FPUsincos(&tmp.x,&sinx,&cosx);
  1191.    FPUsincos(&tmp.y,&siny,&cosy);
  1192.    new.x = old.x - parm.x*siny;
  1193.    new.y = old.y - parm.x*sinx;
  1194.    /*
  1195.    new.x = old.x - parm.x*sin(old.y+tan(3*old.y));
  1196.    new.y = old.y - parm.x*sin(old.x+tan(3*old.x));
  1197.    */
  1198.    if(plot == noplot)
  1199.    {
  1200.       plot_orbit(new.x,new.y,1+row%colors);
  1201.       old = new;
  1202.    }
  1203.    else
  1204.    /* FLOATBAILOUT(); */
  1205.    /* PB The above line was weird, not what it seems to be!  But, bracketing
  1206.      it or always doing it (either of which seem more likely to be what
  1207.      was intended) changes the image for the worse, so I'm not touching it.
  1208.      Same applies to int form in next routine. */
  1209.    /* PB later: recoded inline, still leaving it weird */
  1210.       tempsqrx = sqr(new.x);
  1211.    tempsqry = sqr(new.y);
  1212.    if((magnitude = tempsqrx + tempsqry) >= rqlim) return(1);
  1213.    old = new;
  1214.    return(0);
  1215. }
  1216.  
  1217. LPopcornFractal()
  1218. {
  1219.    extern int row;
  1220.    ltmp = lold;
  1221.    ltmp.x *= 3L;
  1222.    ltmp.y *= 3L;
  1223.    LTRIGARG(ltmp.x);
  1224.    LTRIGARG(ltmp.y);
  1225.    SinCos086(ltmp.x,&lsinx,&lcosx);
  1226.    SinCos086(ltmp.y,&lsiny,&lcosy);
  1227.    ltmp.x = divide(lsinx,lcosx,bitshift) + lold.x;
  1228.    ltmp.y = divide(lsiny,lcosy,bitshift) + lold.y;
  1229.    LTRIGARG(ltmp.x);
  1230.    LTRIGARG(ltmp.y);
  1231.    SinCos086(ltmp.x,&lsinx,&lcosx);
  1232.    SinCos086(ltmp.y,&lsiny,&lcosy);
  1233.    lnew.x = lold.x - multiply(lparm.x,lsiny,bitshift);
  1234.    lnew.y = lold.y - multiply(lparm.x,lsinx,bitshift);
  1235.    if(plot == noplot)
  1236.    {
  1237.       iplot_orbit(lnew.x,lnew.y,1+row%colors);
  1238.       lold = lnew;
  1239.    }
  1240.    else
  1241.       LONGBAILOUT();
  1242.    /* PB above still the old way, is weird, see notes in FP popcorn case */
  1243.    return(0);
  1244. }
  1245.  
  1246. int MarksCplxMand(void)
  1247. {
  1248.    tmp.x = tempsqrx - tempsqry;
  1249.    tmp.y = 2*old.x*old.y;
  1250.    FPUcplxmul(&tmp, &Coefficient, &new);
  1251.    new.x += floatparm->x;
  1252.    new.y += floatparm->y;
  1253.    return(floatbailout());
  1254. }
  1255.  
  1256. int SpiderfpFractal(void)
  1257. {
  1258.    /* Spider(XAXIS) { c=z=pixel: z=z*z+c; c=c/2+z, |z|<=4 } */
  1259.    new.x = tempsqrx - tempsqry + tmp.x;
  1260.    new.y = 2 * old.x * old.y + tmp.y;
  1261.    tmp.x = tmp.x/2 + new.x;
  1262.    tmp.y = tmp.y/2 + new.y;
  1263.    return(floatbailout());
  1264. }
  1265.  
  1266. SpiderFractal(void)
  1267. {
  1268.    /* Spider(XAXIS) { c=z=pixel: z=z*z+c; c=c/2+z, |z|<=4 } */
  1269.    lnew.x  = ltempsqrx - ltempsqry + ltmp.x;
  1270.    lnew.y = multiply(lold.x, lold.y, bitshiftless1) + ltmp.y;
  1271.    ltmp.x = (ltmp.x >> 1) + lnew.x;
  1272.    ltmp.y = (ltmp.y >> 1) + lnew.y;
  1273.    return(longbailout());
  1274. }
  1275.  
  1276. TetratefpFractal()
  1277. {
  1278.    /* Tetrate(XAXIS) { c=z=pixel: z=c^z, |z|<=(P1+3) } */
  1279.    new = ComplexPower(*floatparm,old);
  1280.    return(floatbailout());
  1281. }
  1282.  
  1283. ZXTrigPlusZFractal()
  1284. {
  1285.    /* z = (p1*z*trig(z))+p2*z */
  1286.    LCMPLXtrig0(lold,ltmp);        /* ltmp  = trig(old)         */
  1287.    LCMPLXmult(lparm,ltmp,ltmp);      /* ltmp  = p1*trig(old)          */
  1288.    LCMPLXmult(lold,ltmp,ltmp2);      /* ltmp2 = p1*old*trig(old)      */
  1289.    LCMPLXmult(lparm2,lold,ltmp);     /* ltmp  = p2*old              */
  1290.    LCMPLXadd(ltmp2,ltmp,lnew);         /* lnew  = p1*trig(old) + p2*old */
  1291.    return(longbailout());
  1292. }
  1293.  
  1294. ScottZXTrigPlusZFractal()
  1295. {
  1296.    /* z = (z*trig(z))+z */
  1297.    LCMPLXtrig0(lold,ltmp);        /* ltmp  = trig(old)       */
  1298.    LCMPLXmult(lold,ltmp,lnew);         /* lnew  = old*trig(old)    */
  1299.    LCMPLXadd(lnew,lold,lnew);         /* lnew  = trig(old) + old */
  1300.    return(longbailout());
  1301. }
  1302.  
  1303. SkinnerZXTrigSubZFractal()
  1304. {
  1305.    /* z = (z*trig(z))-z */
  1306.    LCMPLXtrig0(lold,ltmp);        /* ltmp  = trig(old)       */
  1307.    LCMPLXmult(lold,ltmp,lnew);         /* lnew  = old*trig(old)    */
  1308.    LCMPLXsub(lnew,lold,lnew);         /* lnew  = trig(old) - old */
  1309.    return(longbailout());
  1310. }
  1311.  
  1312. ZXTrigPlusZfpFractal()
  1313. {
  1314.    /* z = (p1*z*trig(z))+p2*z */
  1315.    CMPLXtrig0(old,tmp);      /* tmp  = trig(old)         */
  1316.    CMPLXmult(parm,tmp,tmp);     /* tmp  = p1*trig(old)      */
  1317.    CMPLXmult(old,tmp,tmp2);     /* tmp2 = p1*old*trig(old)     */
  1318.    CMPLXmult(parm2,old,tmp);     /* tmp  = p2*old         */
  1319.    CMPLXadd(tmp2,tmp,new);     /* new  = p1*trig(old) + p2*old */
  1320.    return(floatbailout());
  1321. }
  1322.  
  1323. ScottZXTrigPlusZfpFractal()
  1324. {
  1325.    /* z = (z*trig(z))+z */
  1326.    CMPLXtrig0(old,tmp);     /* tmp    = trig(old)      */
  1327.    CMPLXmult(old,tmp,new);     /* new  = old*trig(old)   */
  1328.    CMPLXadd(new,old,new);     /* new  = trig(old) + old */
  1329.    return(floatbailout());
  1330. }
  1331.  
  1332. SkinnerZXTrigSubZfpFractal()
  1333. {
  1334.    /* z = (z*trig(z))-z */
  1335.    CMPLXtrig0(old,tmp);     /* tmp    = trig(old)      */
  1336.    CMPLXmult(old,tmp,new);     /* new  = old*trig(old)   */
  1337.    CMPLXsub(new,old,new);     /* new  = trig(old) - old */
  1338.    return(floatbailout());
  1339. }
  1340.  
  1341. Sqr1overTrigFractal()
  1342. {
  1343.    /* z = sqr(1/trig(z)) */
  1344.    LCMPLXtrig0(lold,lold);
  1345.    LCMPLXrecip(lold,lold);
  1346.    LCMPLXsqr(lold,lnew);
  1347.    return(longbailout());
  1348. }
  1349.  
  1350. Sqr1overTrigfpFractal()
  1351. {
  1352.    /* z = sqr(1/trig(z)) */
  1353.    CMPLXtrig0(old,old);
  1354.    CMPLXrecip(old,old);
  1355.    CMPLXsqr(old,new);
  1356.    return(floatbailout());
  1357. }
  1358.  
  1359. TrigPlusTrigFractal()
  1360. {
  1361.    /* z = trig(0,z)*p1+trig1(z)*p2 */
  1362.    LCMPLXtrig0(lold,ltmp);
  1363.    LCMPLXmult(lparm,ltmp,ltmp);
  1364.    LCMPLXtrig1(lold,ltmp2);
  1365.    LCMPLXmult(lparm2,ltmp2,lold);
  1366.    LCMPLXadd(ltmp,lold,lnew);
  1367.    return(longbailout());
  1368. }
  1369.  
  1370. TrigPlusTrigfpFractal()
  1371. {
  1372.    /* z = trig0(z)*p1+trig1(z)*p2 */
  1373.    CMPLXtrig0(old,tmp);
  1374.    CMPLXmult(parm,tmp,tmp);
  1375.    CMPLXtrig1(old,old);
  1376.    CMPLXmult(parm2,old,old);
  1377.    CMPLXadd(tmp,old,new);
  1378.    return(floatbailout());
  1379. }
  1380.  
  1381.  
  1382. ScottTrigPlusTrigFractal()
  1383. {
  1384.    /* z = trig0(z)+trig1(z) */
  1385.    LCMPLXtrig0(lold,ltmp);
  1386.    LCMPLXtrig1(lold,lold);
  1387.    LCMPLXadd(ltmp,lold,lnew);
  1388.    return(longbailout());
  1389. }
  1390.  
  1391. ScottTrigPlusTrigfpFractal()
  1392. {
  1393.    /* z = trig0(z)+trig1(z) */
  1394.    CMPLXtrig0(old,tmp);
  1395.    CMPLXtrig1(old,tmp2);
  1396.    CMPLXadd(tmp,tmp2,new);
  1397.    return(floatbailout());
  1398. }
  1399.  
  1400. SkinnerTrigSubTrigFractal()
  1401. {
  1402.    /* z = trig(0,z)-trig1(z) */
  1403.    LCMPLXtrig0(lold,ltmp);
  1404.    LCMPLXtrig1(lold,ltmp2);
  1405.    LCMPLXsub(ltmp,ltmp2,lnew);
  1406.    return(longbailout());
  1407. }
  1408.  
  1409. SkinnerTrigSubTrigfpFractal()
  1410. {
  1411.    /* z = trig0(z)-trig1(z) */
  1412.    CMPLXtrig0(old,tmp);
  1413.    CMPLXtrig1(old,tmp2);
  1414.    CMPLXsub(tmp,tmp2,new);
  1415.    return(floatbailout());
  1416. }
  1417.  
  1418.  
  1419. TrigXTrigfpFractal()
  1420. {
  1421.    /* z = trig0(z)*trig1(z) */
  1422.    CMPLXtrig0(old,tmp);
  1423.    CMPLXtrig1(old,old);
  1424.    CMPLXmult(tmp,old,new);
  1425.    return(floatbailout());
  1426. }
  1427.  
  1428. TrigXTrigFractal()
  1429. {
  1430.    LCMPLX ltmp2;
  1431.    /* z = trig0(z)*trig1(z) */
  1432.    LCMPLXtrig0(lold,ltmp);
  1433.    LCMPLXtrig1(lold,ltmp2);
  1434.    LCMPLXmult(ltmp,ltmp2,lnew);
  1435.    if(overflow)
  1436.       TryFloatFractal(TrigXTrigfpFractal);
  1437.    return(longbailout());
  1438. }
  1439.  
  1440.  /* call float version of fractal if integer math overflow */
  1441. TryFloatFractal(int (*fpFractal)())
  1442. {
  1443.    overflow=0;
  1444.    /* lold had better not be changed! */
  1445.    old.x = lold.x; old.x /= fudge;
  1446.    old.y = lold.y; old.y /= fudge;
  1447.    tempsqrx = sqr(old.x);
  1448.    tempsqry = sqr(old.y);
  1449.    fpFractal();
  1450.    lnew.x = new.x/fudge;
  1451.    lnew.y = new.y/fudge;
  1452.    return(0);
  1453. }
  1454.  
  1455. /********************************************************************/
  1456. /*  Next six orbit functions are one type - extra functions are     */
  1457. /*    special cases written for speed.                    */
  1458. /********************************************************************/
  1459.  
  1460. TrigPlusSqrFractal() /* generalization of Scott and Skinner types */
  1461. {
  1462.    /* { z=pixel: z=(p1,p2)*trig(z)+(p3,p4)*sqr(z), |z|<BAILOUT } */
  1463.    LCMPLXtrig0(lold,ltmp);     /* ltmp = trig(lold)               */
  1464.    LCMPLXmult(lparm,ltmp,lnew); /* lnew = lparm*trig(lold)            */
  1465.    LCMPLXsqr_old(ltmp);     /* ltmp = sqr(lold)                */
  1466.    LCMPLXmult(lparm2,ltmp,ltmp);/* ltmp = lparm2*sqr(lold)            */
  1467.    LCMPLXadd(lnew,ltmp,lnew);    /* lnew = lparm*trig(lold)+lparm2*sqr(lold) */
  1468.    return(longbailout());
  1469. }
  1470.  
  1471. TrigPlusSqrfpFractal() /* generalization of Scott and Skinner types */
  1472. {
  1473.    /* { z=pixel: z=(p1,p2)*trig(z)+(p3,p4)*sqr(z), |z|<BAILOUT } */
  1474.    CMPLXtrig0(old,tmp);     /* tmp = trig(old)               */
  1475.    CMPLXmult(parm,tmp,new); /* new = parm*trig(old)           */
  1476.    CMPLXsqr_old(tmp);         /* tmp = sqr(old)                */
  1477.    CMPLXmult(parm2,tmp,tmp2); /* tmp = parm2*sqr(old)             */
  1478.    CMPLXadd(new,tmp2,new);    /* new = parm*trig(old)+parm2*sqr(old) */
  1479.    return(floatbailout());
  1480. }
  1481.  
  1482. ScottTrigPlusSqrFractal()
  1483. {
  1484.    /*  { z=pixel: z=trig(z)+sqr(z), |z|<BAILOUT } */
  1485.    LCMPLXtrig0(lold,lnew);    /* lnew = trig(lold)         */
  1486.    LCMPLXsqr_old(ltmp);        /* lold = sqr(lold)          */
  1487.    LCMPLXadd(ltmp,lnew,lnew);  /* lnew = trig(lold)+sqr(lold) */
  1488.    return(longbailout());
  1489. }
  1490.  
  1491. ScottTrigPlusSqrfpFractal() /* float version */
  1492. {
  1493.    /* { z=pixel: z=sin(z)+sqr(z), |z|<BAILOUT } */
  1494.    CMPLXtrig0(old,new);       /* new = trig(old)      */
  1495.    CMPLXsqr_old(tmp);           /* tmp = sqr(old)       */
  1496.    CMPLXadd(new,tmp,new);      /* new = trig(old)+sqr(old) */
  1497.    return(floatbailout());
  1498. }
  1499.  
  1500. SkinnerTrigSubSqrFractal()
  1501. {
  1502.    /* { z=pixel: z=sin(z)-sqr(z), |z|<BAILOUT }           */
  1503.    LCMPLXtrig0(lold,lnew);    /* lnew = trig(lold)         */
  1504.    LCMPLXsqr_old(ltmp);        /* lold = sqr(lold)          */
  1505.    LCMPLXsub(lnew,ltmp,lnew);  /* lnew = trig(lold)-sqr(lold) */
  1506.    return(longbailout());
  1507. }
  1508.  
  1509. SkinnerTrigSubSqrfpFractal()
  1510. {
  1511.    /* { z=pixel: z=sin(z)-sqr(z), |z|<BAILOUT } */
  1512.    CMPLXtrig0(old,new);       /* new = trig(old) */
  1513.    CMPLXsqr_old(tmp);           /* old = sqr(old)  */
  1514.    CMPLXsub(new,tmp,new);      /* new = trig(old)-sqr(old) */
  1515.    return(floatbailout());
  1516. }
  1517.  
  1518. TrigZsqrdfpFractal()
  1519. {
  1520.    /* { z=pixel: z=trig(z*z), |z|<TEST } */
  1521.    CMPLXsqr_old(tmp);
  1522.    CMPLXtrig0(tmp,new);
  1523.    return(floatbailout());
  1524. }
  1525.  
  1526. TrigZsqrdFractal() /* this doesn't work very well */
  1527. {
  1528.    /* { z=pixel: z=trig(z*z), |z|<TEST } */
  1529.    LCMPLXsqr_old(ltmp);
  1530.    LCMPLXtrig0(ltmp,lnew);
  1531.    if(overflow)
  1532.       TryFloatFractal(TrigZsqrdfpFractal);
  1533.    return(longbailout());
  1534. }
  1535.  
  1536. SqrTrigFractal()
  1537. {
  1538.    /* { z=pixel: z=sqr(trig(z)), |z|<TEST} */
  1539.    LCMPLXtrig0(lold,ltmp);
  1540.    LCMPLXsqr(ltmp,lnew);
  1541.    return(longbailout());
  1542. }
  1543.  
  1544. SqrTrigfpFractal()
  1545. {
  1546.    /* SZSB(XYAXIS) { z=pixel, TEST=(p1+3): z=sin(z)*sin(z), |z|<TEST} */
  1547.    CMPLXtrig0(old,tmp);
  1548.    CMPLXsqr(tmp,new);
  1549.    return(floatbailout());
  1550. }
  1551.  
  1552.  
  1553. Magnet1Fractal()    /*      Z = ((Z**2 + C - 1)/(2Z + C - 2))**2      */
  1554.   {              /*  In "Beauty of Fractals", code by Kev Allen. */
  1555.     CMPLX top, bot, tmp;
  1556.     double div;
  1557.  
  1558.     top.x = tempsqrx - tempsqry + floatparm->x - 1; /* top = Z**2+C-1 */
  1559.     top.y = old.x * old.y;
  1560.     top.y = top.y + top.y + floatparm->y;
  1561.  
  1562.     bot.x = old.x + old.x + floatparm->x - 2;        /* bot = 2*Z+C-2  */
  1563.     bot.y = old.y + old.y + floatparm->y;
  1564.  
  1565.     div = bot.x*bot.x + bot.y*bot.y;            /* tmp = top/bot  */
  1566.     if (div < FLT_MIN) return(1);
  1567.     tmp.x = (top.x*bot.x + top.y*bot.y)/div;
  1568.     tmp.y = (top.y*bot.x - top.x*bot.y)/div;
  1569.  
  1570.     new.x = (tmp.x + tmp.y) * (tmp.x - tmp.y);        /* Z = tmp**2     */
  1571.     new.y = tmp.x * tmp.y;
  1572.     new.y += new.y;
  1573.  
  1574.     return(floatbailout());
  1575.   }
  1576.  
  1577. Magnet2Fractal()  /* Z = ((Z**3 + 3(C-1)Z + (C-1)(C-2)    ) /     */
  1578.             /*         (3Z**2 + 3(C-2)Z + (C-1)(C-2)+1) )**2  */
  1579.   {            /*     In "Beauty of Fractals", code by Kev Allen.  */
  1580.     CMPLX top, bot, tmp;
  1581.     double div;
  1582.  
  1583.     top.x = old.x * (tempsqrx-tempsqry-tempsqry-tempsqry + T_Cm1.x)
  1584.       - old.y * T_Cm1.y + T_Cm1Cm2.x;
  1585.     top.y = old.y * (tempsqrx+tempsqrx+tempsqrx-tempsqry + T_Cm1.x)
  1586.       + old.x * T_Cm1.y + T_Cm1Cm2.y;
  1587.  
  1588.     bot.x = tempsqrx - tempsqry;
  1589.     bot.x = bot.x + bot.x + bot.x
  1590.       + old.x * T_Cm2.x - old.y * T_Cm2.y
  1591.       + T_Cm1Cm2.x + 1.0;
  1592.     bot.y = old.x * old.y;
  1593.     bot.y += bot.y;
  1594.     bot.y = bot.y + bot.y + bot.y
  1595.       + old.x * T_Cm2.y + old.y * T_Cm2.x
  1596.       + T_Cm1Cm2.y;
  1597.  
  1598.     div = bot.x*bot.x + bot.y*bot.y;            /* tmp = top/bot  */
  1599.     if (div < FLT_MIN) return(1);
  1600.     tmp.x = (top.x*bot.x + top.y*bot.y)/div;
  1601.     tmp.y = (top.y*bot.x - top.x*bot.y)/div;
  1602.  
  1603.     new.x = (tmp.x + tmp.y) * (tmp.x - tmp.y);        /* Z = tmp**2     */
  1604.     new.y = tmp.x * tmp.y;
  1605.     new.y += new.y;
  1606.  
  1607.     return(floatbailout());
  1608.   }
  1609.  
  1610. LambdaTrigFractal()
  1611. {
  1612.    LONGXYTRIGBAILOUT();
  1613.    LCMPLXtrig0(lold,ltmp);         /* ltmp = trig(lold)        */
  1614.    LCMPLXmult(*longparm,ltmp,lnew);   /* lnew = longparm*trig(lold)  */
  1615.    lold = lnew;
  1616.    return(0);
  1617. }
  1618.  
  1619. LambdaTrigfpFractal()
  1620. {
  1621.    FLOATXYTRIGBAILOUT();
  1622.    CMPLXtrig0(old,tmp);          /* tmp = trig(old)       */
  1623.    CMPLXmult(*floatparm,tmp,new);   /* new = longparm*trig(old)  */
  1624.    old = new;
  1625.    return(0);
  1626. }
  1627.  
  1628. /* bailouts are different for different trig functions */
  1629. LambdaTrigFractal1()
  1630. {
  1631.    LONGTRIGBAILOUT(); /* sin,cos */
  1632.    LCMPLXtrig0(lold,ltmp);         /* ltmp = trig(lold)        */
  1633.    LCMPLXmult(*longparm,ltmp,lnew);   /* lnew = longparm*trig(lold)  */
  1634.    lold = lnew;
  1635.    return(0);
  1636. }
  1637.  
  1638. LambdaTrigfpFractal1()
  1639. {
  1640.    FLOATTRIGBAILOUT(); /* sin,cos */
  1641.    CMPLXtrig0(old,tmp);          /* tmp = trig(old)       */
  1642.    CMPLXmult(*floatparm,tmp,new);   /* new = longparm*trig(old)  */
  1643.    old = new;
  1644.    return(0);
  1645. }
  1646.  
  1647. LambdaTrigFractal2()
  1648. {
  1649.    LONGHTRIGBAILOUT(); /* sinh,cosh */
  1650.    LCMPLXtrig0(lold,ltmp);         /* ltmp = trig(lold)        */
  1651.    LCMPLXmult(*longparm,ltmp,lnew);   /* lnew = longparm*trig(lold)  */
  1652.    lold = lnew;
  1653.    return(0);
  1654. }
  1655.  
  1656. LambdaTrigfpFractal2()
  1657. {
  1658.    FLOATHTRIGBAILOUT(); /* sinh,cosh */
  1659.    CMPLXtrig0(old,tmp);          /* tmp = trig(old)       */
  1660.    CMPLXmult(*floatparm,tmp,new);   /* new = longparm*trig(old)  */
  1661.    old = new;
  1662.    return(0);
  1663. }
  1664.  
  1665. ManOWarFractal()
  1666. {
  1667.    /* From Art Matrix via Lee Skinner */
  1668.    lnew.x  = ltempsqrx - ltempsqry + ltmp.x + longparm->x;
  1669.    lnew.y = multiply(lold.x, lold.y, bitshiftless1) + ltmp.y + longparm->y;
  1670.    ltmp = lold;
  1671.    return(longbailout());
  1672. }
  1673.  
  1674. ManOWarfpFractal()
  1675. {
  1676.    /* From Art Matrix via Lee Skinner */
  1677.    /* note that fast >= 287 equiv in fracsuba.asm must be kept in step */
  1678.    new.x = tempsqrx - tempsqry + tmp.x + floatparm->x;
  1679.    new.y = 2.0 * old.x * old.y + tmp.y + floatparm->y;
  1680.    tmp = old;
  1681.    return(floatbailout());
  1682. }
  1683.  
  1684. /*
  1685.    MarksMandelPwr (XAXIS) {
  1686.       z = pixel, c = z ^ (z - 1):
  1687.      z = c * sqr(z) + pixel,
  1688.       |z| <= 4
  1689.    }
  1690. */
  1691.  
  1692. MarksMandelPwrfpFractal()
  1693. {
  1694.    CMPLXtrig0(old,new);
  1695.    CMPLXmult(tmp,new,new);
  1696.    new.x += floatparm->x;
  1697.    new.y += floatparm->y;
  1698.    return(floatbailout());
  1699. }
  1700.  
  1701. MarksMandelPwrFractal()
  1702. {
  1703.    LCMPLXtrig0(lold,lnew);
  1704.    LCMPLXmult(ltmp,lnew,lnew);
  1705.    lnew.x += longparm->x;
  1706.    lnew.y += longparm->y;
  1707.    return(longbailout());
  1708. }
  1709.  
  1710. /* I was coding Marksmandelpower and failed to use some temporary
  1711.    variables. The result was nice, and since my name is not on any fractal,
  1712.    I thought I would immortalize myself with this error!
  1713.         Tim Wegner */
  1714.  
  1715.  
  1716. TimsErrorfpFractal()
  1717. {
  1718.    CMPLXtrig0(old,new);
  1719.    new.x = new.x * tmp.x - new.y * tmp.y;
  1720.    new.y = new.x * tmp.y - new.y * tmp.x;
  1721.    new.x += floatparm->x;
  1722.    new.y += floatparm->y;
  1723.    return(floatbailout());
  1724. }
  1725. TimsErrorFractal()
  1726. {
  1727.    LCMPLXtrig0(lold,lnew);
  1728.    lnew.x = multiply(lnew.x,ltmp.x,bitshift)-multiply(lnew.y,ltmp.y,bitshift);
  1729.    lnew.y = multiply(lnew.x,ltmp.y,bitshift)-multiply(lnew.y,ltmp.x,bitshift);
  1730.    lnew.x += longparm->x;
  1731.    lnew.y += longparm->y;
  1732.    return(longbailout());
  1733. }
  1734.  
  1735. CirclefpFractal()
  1736. {
  1737.    extern int colors;
  1738.    extern int color;
  1739.    int i;
  1740.    i = param[0]*(tempsqrx+tempsqry);
  1741.    color = i&(colors-1);
  1742.    return(1);
  1743. }
  1744. /*
  1745. CirclelongFractal()
  1746. {
  1747.    extern int colors;
  1748.    extern int color;
  1749.    long i;
  1750.    i = multiply(lparm.x,(ltempsqrx+ltempsqry),bitshift);
  1751.    i = i >> bitshift;
  1752.    color = i&(colors-1);
  1753.    return(1);
  1754. }
  1755. */
  1756.  
  1757. /* -------------------------------------------------------------------- */
  1758. /*        Initialization (once per pixel) routines                        */
  1759. /* -------------------------------------------------------------------- */
  1760.  
  1761. #if 0
  1762. /* this code translated to asm - lives in newton.asm */
  1763. /* transform points with reciprocal function */
  1764. void invertz1(CMPLX *z)
  1765. {
  1766.    z->x = dx0[col]+dx1[row];
  1767.    z->y = dy0[row]+dy1[col];
  1768.    z->x -= f_xcenter; z->y -= f_ycenter;  /* Normalize values to center of circle */
  1769.  
  1770.    tempsqrx = sqr(z->x) + sqr(z->y);  /* Get old radius */
  1771.    if(fabs(tempsqrx) > FLT_MIN)
  1772.       tempsqrx = f_radius / tempsqrx;
  1773.    else
  1774.       tempsqrx = FLT_MAX;   /* a big number, but not TOO big */
  1775.    z->x *= tempsqrx;      z->y *= tempsqrx;     /* Perform inversion */
  1776.    z->x += f_xcenter; z->y += f_ycenter; /* Renormalize */
  1777. }
  1778. #endif
  1779.  
  1780. int long_julia_per_pixel()
  1781. {
  1782.    /* integer julia types */
  1783.    /* lambda */
  1784.    /* barnsleyj1 */
  1785.    /* barnsleyj2 */
  1786.    /* sierpinski */
  1787.    if(invert)
  1788.    {
  1789.       /* invert */
  1790.       invertz2(&old);
  1791.  
  1792.       /* watch out for overflow */
  1793.       if(sqr(old.x)+sqr(old.y) >= 127)
  1794.       {
  1795.      old.x = 8;  /* value to bail out in one iteration */
  1796.      old.y = 8;
  1797.       }
  1798.  
  1799.       /* convert to fudged longs */
  1800.       lold.x = old.x*fudge;
  1801.       lold.y = old.y*fudge;
  1802.    }
  1803.    else
  1804.    {
  1805.       lold.x = lx0[col]+lx1[row];
  1806.       lold.y = ly0[row]+ly1[col];
  1807.    }
  1808.    ltempsqrx = multiply(lold.x, lold.x, bitshift);
  1809.    ltempsqry = multiply(lold.y, lold.y, bitshift);
  1810.    ltmp = lold;
  1811.    return(0);
  1812. }
  1813.  
  1814. int long_richard8_per_pixel()
  1815. {
  1816.     long_mandel_per_pixel();
  1817.     LCMPLXtrig1(*longparm,ltmp);
  1818.     LCMPLXmult(ltmp,lparm2,ltmp);
  1819.     return(1);
  1820. }
  1821.  
  1822. int long_mandel_per_pixel()
  1823. {
  1824.    /* integer mandel types */
  1825.    /* barnsleym1 */
  1826.    /* barnsleym2 */
  1827.    linit.x = lx0[col]+lx1[row];
  1828.  
  1829.    if(invert)
  1830.    {
  1831.       /* invert */
  1832.       invertz2(&init);
  1833.  
  1834.       /* watch out for overflow */
  1835.       if(sqr(init.x)+sqr(init.y) >= 127)
  1836.       {
  1837.      init.x = 8;  /* value to bail out in one iteration */
  1838.      init.y = 8;
  1839.       }
  1840.  
  1841.       /* convert to fudged longs */
  1842.       linit.x = init.x*fudge;
  1843.       linit.y = init.y*fudge;
  1844.    }
  1845.  
  1846.    if(useinitorbit == 1)
  1847.       lold = linitorbit;
  1848.    else
  1849.       lold = linit;
  1850.  
  1851.    lold.x += lparm.x;     /* initial pertubation of parameters set */
  1852.    lold.y += lparm.y;
  1853.    ltempsqrx = multiply(lold.x, lold.x, bitshift);
  1854.    ltempsqry = multiply(lold.y, lold.y, bitshift);
  1855.    return(1); /* 1st iteration has been done */
  1856. }
  1857.  
  1858. int julia_per_pixel()
  1859. {
  1860.    /* julia */
  1861.  
  1862.    if(invert)
  1863.    {
  1864.       /* invert */
  1865.       invertz2(&old);
  1866.  
  1867.       /* watch out for overflow */
  1868.       if(bitshift <= 24)
  1869.      if (sqr(old.x)+sqr(old.y) >= 127)
  1870.      {
  1871.         old.x = 8;    /* value to bail out in one iteration */
  1872.         old.y = 8;
  1873.      }
  1874.       if(bitshift >  24)
  1875.      if (sqr(old.x)+sqr(old.y) >= 4.0)
  1876.      {
  1877.         old.x = 2;    /* value to bail out in one iteration */
  1878.         old.y = 2;
  1879.      }
  1880.  
  1881.       /* convert to fudged longs */
  1882.       lold.x = old.x*fudge;
  1883.       lold.y = old.y*fudge;
  1884.    }
  1885.    else
  1886.    {
  1887.       lold.x = lx0[col]+lx1[row];
  1888.       lold.y = ly0[row]+ly1[col];
  1889.    }
  1890.  
  1891.    ltempsqrx = multiply(lold.x, lold.x, bitshift);
  1892.    ltempsqry = multiply(lold.y, lold.y, bitshift);
  1893.    ltmp = lold;
  1894.    return(0);
  1895. }
  1896.  
  1897. marks_mandelpwr_per_pixel()
  1898. {
  1899.    mandel_per_pixel();
  1900.    ltmp = lold;
  1901.    ltmp.x -= fudge;
  1902.    LCMPLXpwr(lold,ltmp,ltmp);
  1903.    return(1);
  1904. }
  1905.  
  1906. int mandel_per_pixel()
  1907. {
  1908.    /* mandel */
  1909.  
  1910.    if(invert)
  1911.    {
  1912.       invertz2(&init);
  1913.  
  1914.       /* watch out for overflow */
  1915.       if(bitshift <= 24)
  1916.      if (sqr(init.x)+sqr(init.y) >= 127)
  1917.      {
  1918.         init.x = 8;  /* value to bail out in one iteration */
  1919.         init.y = 8;
  1920.      }
  1921.       if(bitshift >  24)
  1922.      if (sqr(init.x)+sqr(init.y) >= 4)
  1923.      {
  1924.         init.x = 2;  /* value to bail out in one iteration */
  1925.         init.y = 2;
  1926.      }
  1927.  
  1928.       /* convert to fudged longs */
  1929.       linit.x = init.x*fudge;
  1930.       linit.y = init.y*fudge;
  1931.    }
  1932.    else
  1933.       linit.x = lx0[col]+lx1[row];
  1934.    switch (fractype)
  1935.      {
  1936.     case MANDELLAMBDA:        /* Critical Value 0.5 + 0.0i  */
  1937.         lold.x = FgHalf;
  1938.         lold.y = 0;
  1939.         break;
  1940.     default:
  1941.         lold = linit;
  1942.         break;
  1943.       }
  1944.  
  1945.    /* alter init value */
  1946.    if(useinitorbit == 1)
  1947.       lold = linitorbit;
  1948.    else if(useinitorbit == 2)
  1949.       lold = linit;
  1950.  
  1951.    if(inside == -60 || inside == -61)
  1952.    {
  1953.       /* kludge to match "Beauty of Fractals" picture since we start
  1954.      Mandelbrot iteration with init rather than 0 */
  1955.       lold.x = lparm.x; /* initial pertubation of parameters set */
  1956.       lold.y = lparm.y;
  1957.       color = -1;
  1958.    }
  1959.    else
  1960.    {
  1961.       lold.x += lparm.x; /* initial pertubation of parameters set */
  1962.       lold.y += lparm.y;
  1963.    }
  1964.    ltmp = linit; /* for spider */
  1965.    ltempsqrx = multiply(lold.x, lold.x, bitshift);
  1966.    ltempsqry = multiply(lold.y, lold.y, bitshift);
  1967.    return(1); /* 1st iteration has been done */
  1968. }
  1969.  
  1970.  
  1971. int marksmandel_per_pixel()
  1972. {
  1973.    /* marksmandel */
  1974.  
  1975.    if(invert)
  1976.    {
  1977.       invertz2(&init);
  1978.  
  1979.       /* watch out for overflow */
  1980.       if(sqr(init.x)+sqr(init.y) >= 127)
  1981.       {
  1982.      init.x = 8;  /* value to bail out in one iteration */
  1983.      init.y = 8;
  1984.       }
  1985.  
  1986.       /* convert to fudged longs */
  1987.       linit.x = init.x*fudge;
  1988.       linit.y = init.y*fudge;
  1989.    }
  1990.    else
  1991.       linit.x = lx0[col]+lx1[row];
  1992.  
  1993.    if(useinitorbit == 1)
  1994.       lold = linitorbit;
  1995.    else
  1996.       lold = linit;
  1997.  
  1998.    lold.x += lparm.x;     /* initial pertubation of parameters set */
  1999.    lold.y += lparm.y;
  2000.  
  2001.    if(c_exp > 3)
  2002.       lcpower(&lold,c_exp-1,&lcoefficient,bitshift);
  2003.    else if(c_exp == 3) {
  2004.       lcoefficient.x = multiply(lold.x, lold.x, bitshift)
  2005.      - multiply(lold.y, lold.y, bitshift);
  2006.       lcoefficient.y = multiply(lold.x, lold.y, bitshiftless1);
  2007.    }
  2008.    else if(c_exp == 2)
  2009.       lcoefficient = lold;
  2010.    else if(c_exp < 2) {
  2011.       lcoefficient.x = 1L << bitshift;
  2012.       lcoefficient.y = 0L;
  2013.    }
  2014.  
  2015.    ltempsqrx = multiply(lold.x, lold.x, bitshift);
  2016.    ltempsqry = multiply(lold.y, lold.y, bitshift);
  2017.    return(1); /* 1st iteration has been done */
  2018. }
  2019.  
  2020. marks_mandelpwrfp_per_pixel()
  2021. {
  2022.    mandelfp_per_pixel();
  2023.    tmp = old;
  2024.    tmp.x -= 1;
  2025.    CMPLXpwr(old,tmp,tmp);
  2026.    return(1);
  2027. }
  2028.  
  2029. int mandelfp_per_pixel()
  2030. {
  2031.    /* floating point mandelbrot */
  2032.    /* mandelfp */
  2033.  
  2034.    if(invert)
  2035.       invertz2(&init);
  2036.    else
  2037.       init.x = dx0[col]+dx1[row];
  2038.     switch (fractype)
  2039.       {
  2040.     case MAGNET2M:
  2041.         FloatPreCalcMagnet2();
  2042.     case MAGNET1M:         /* Crit Val Zero both, but neither   */
  2043.         old.x = old.y = 0.0; /* is of the form f(Z,C) = Z*g(Z)+C  */
  2044.         break;
  2045.     case MANDELLAMBDAFP:        /* Critical Value 0.5 + 0.0i  */
  2046.         old.x = 0.5;
  2047.         old.y = 0.0;
  2048.         break;
  2049.     default:
  2050.         old = init;
  2051.         break;
  2052.       }
  2053.  
  2054.    /* alter init value */
  2055.    if(useinitorbit == 1)
  2056.       old = initorbit;
  2057.    else if(useinitorbit == 2)
  2058.       old = init;
  2059.  
  2060.    if(inside == -60 || inside == -61)
  2061.    {
  2062.       /* kludge to match "Beauty of Fractals" picture since we start
  2063.      Mandelbrot iteration with init rather than 0 */
  2064.       old.x = parm.x; /* initial pertubation of parameters set */
  2065.       old.y = parm.y;
  2066.       color = -1;
  2067.    }
  2068.    else
  2069.    {
  2070.      old.x += parm.x;
  2071.      old.y += parm.y;
  2072.    }
  2073.    tmp = init; /* for spider */
  2074.    tempsqrx = sqr(old.x);  /* precalculated value for regular Mandelbrot */
  2075.    tempsqry = sqr(old.y);
  2076.    return(1); /* 1st iteration has been done */
  2077. }
  2078.  
  2079. int juliafp_per_pixel()
  2080. {
  2081.    /* floating point julia */
  2082.    /* juliafp */
  2083.    if(invert)
  2084.       invertz2(&old);
  2085.    else
  2086.    {
  2087.      old.x = dx0[col]+dx1[row];
  2088.      old.y = dy0[row]+dy1[col];
  2089.    }
  2090.    tempsqrx = sqr(old.x);  /* precalculated value for regular Julia */
  2091.    tempsqry = sqr(old.y);
  2092.    tmp = old;
  2093.    return(0);
  2094. }
  2095.  
  2096. int MPCjulia_per_pixel()
  2097. {
  2098.    /* floating point julia */
  2099.    /* juliafp */
  2100.    if(invert)
  2101.       invertz2(&old);
  2102.    else
  2103.    {
  2104.      old.x = dx0[col]+dx1[row];
  2105.      old.y = dy0[row]+dy1[col];
  2106.    }
  2107.    mpcold.x = *pd2MP(old.x);
  2108.    mpcold.y = *pd2MP(old.y);
  2109.    return(0);
  2110. }
  2111.  
  2112. otherrichard8fp_per_pixel()
  2113. {
  2114.     othermandelfp_per_pixel();
  2115.     CMPLXtrig1(*floatparm,tmp);
  2116.     CMPLXmult(tmp,parm2,tmp);
  2117.     return(1);
  2118. }
  2119.  
  2120. int othermandelfp_per_pixel()
  2121. {
  2122.    if(invert)
  2123.       invertz2(&init);
  2124.    else
  2125.       init.x = dx0[col]+dx1[row];
  2126.  
  2127.    if(useinitorbit == 1)
  2128.       old = initorbit;
  2129.    else
  2130.       old = init;
  2131.  
  2132.    old.x += parm.x;     /* initial pertubation of parameters set */
  2133.    old.y += parm.y;
  2134.  
  2135.    tempsqrx = sqr(old.x);  /* precalculated value for regular Mandelbrot */
  2136.    tempsqry = sqr(old.y);
  2137.    return(1); /* 1st iteration has been done */
  2138. }
  2139.  
  2140. int otherjuliafp_per_pixel()
  2141. {
  2142.    if(invert)
  2143.       invertz2(&old);
  2144.    else
  2145.    {
  2146.       old.x = dx0[col]+dx1[row];
  2147.       old.y = dy0[row]+dy1[col];
  2148.    }
  2149.    tempsqrx = sqr(old.x);  /* precalculated value for regular Julia */
  2150.    tempsqry = sqr(old.y);
  2151.    tmp = old;
  2152.    return(0);
  2153. }
  2154.  
  2155. int trigmandelfp_per_pixel()
  2156. {
  2157.    if(invert)
  2158.       invertz2(&init);
  2159.    else
  2160.       init.x = dx0[col]+dx1[row];
  2161.  
  2162.    if(useinitorbit == 1)
  2163.       old = initorbit;
  2164.    else
  2165.       old = init;
  2166.  
  2167.    old.x += parm.x;     /* initial pertubation of parameters set */
  2168.    old.y += parm.y;
  2169.    CMPLXtrig0(old,old);
  2170.    return(1); /* 1st iteration has been done */
  2171. }
  2172.  
  2173. int trigjuliafp_per_pixel()
  2174. {
  2175.    /* for tetrated types */
  2176.    if(invert)
  2177.       invertz2(&old);
  2178.    else
  2179.    {
  2180.       old.x = dx0[col]+dx1[row];
  2181.       old.y = dy0[row]+dy1[col];
  2182.    }
  2183.    CMPLXtrig0(old,old);
  2184.    return(0);
  2185. }
  2186.  
  2187. int trigXtrigmandelfp_per_pixel()
  2188. {
  2189.    if(invert)
  2190.       invertz2(&init);
  2191.    else
  2192.       init.x = dx0[col]+dx1[row];
  2193.  
  2194.    if(useinitorbit == 1)
  2195.       old = initorbit;
  2196.    else
  2197.       old = init;
  2198.  
  2199.    old.x += parm.x;     /* initial pertubation of parameters set */
  2200.    old.y += parm.y;
  2201.    CMPLXtrig0(old,tmp);
  2202.    CMPLXtrig1(old,tmp2);
  2203.    CMPLXmult(tmp,tmp2,old);
  2204.    return(1); /* 1st iteration has been done */
  2205. }
  2206.  
  2207. int trigXtrigjuliafp_per_pixel()
  2208. {
  2209.    if(invert)
  2210.       invertz2(&old);
  2211.    else
  2212.    {
  2213.       old.x = dx0[col]+dx1[row];
  2214.       old.y = dy0[row]+dy1[col];
  2215.    }
  2216.    CMPLXtrig0(old,tmp);
  2217.    CMPLXtrig1(old,tmp2);
  2218.    CMPLXmult(tmp,tmp2,old);
  2219.    return(0);
  2220. }
  2221.  
  2222. int MarksCplxMandperp(void)
  2223. {
  2224.    if(invert)
  2225.       invertz2(&init);
  2226.    else
  2227.       init.x = dx0[col]+dx1[row];
  2228.    old.x = init.x + parm.x; /* initial pertubation of parameters set */
  2229.    old.y = init.y + parm.y;
  2230.    tempsqrx = sqr(old.x);  /* precalculated value */
  2231.    tempsqry = sqr(old.y);
  2232.    Coefficient = ComplexPower(init, pwr);
  2233.    return(1);
  2234. }
  2235.  
  2236. /* -------------------------------------------------------------------- */
  2237. /*        Setup (once per fractal image) routines         */
  2238. /* -------------------------------------------------------------------- */
  2239.  
  2240. MandelSetup()        /* Mandelbrot Routine */
  2241. {
  2242.    if (debugflag != 90 && ! invert && decomp[0] == 0 && rqlim <= 4.0
  2243.        && bitshift == 29 && potflag == 0
  2244.        && biomorph == -1 && inside > -59 && outside == -1
  2245.        && useinitorbit != 1)
  2246.       calctype = calcmand; /* the normal case - use CALCMAND */
  2247.    else
  2248.    {
  2249.       /* special case: use the main processing loop */
  2250.       calctype = StandardFractal;
  2251.       longparm = &linit;
  2252.    }
  2253.    return(1);
  2254. }
  2255.  
  2256. JuliaSetup()        /* Julia Routine */
  2257. {
  2258.    if (debugflag != 90 && ! invert && decomp[0] == 0 && rqlim <= 4.0
  2259.        && bitshift == 29 && potflag == 0
  2260.        && biomorph == -1 && inside > -59 && outside == -1
  2261.        && !finattract)
  2262.       calctype = calcmand; /* the normal case - use CALCMAND */
  2263.    else
  2264.    {
  2265.       /* special case: use the main processing loop */
  2266.       calctype = StandardFractal;
  2267.       longparm = &lparm;
  2268.       get_julia_attractor (0.0, 0.0);    /* another attractor? */
  2269.    }
  2270.    return(1);
  2271. }
  2272.  
  2273. NewtonSetup()        /* Newton/NewtBasin Routines */
  2274. {
  2275.    int i;
  2276.    extern int basin;
  2277.    extern int fpu;
  2278.    if (debugflag != 1010)
  2279.    {
  2280.       if(fpu != 0)
  2281.       {
  2282.      if(fractype == MPNEWTON)
  2283.         fractype = NEWTON;
  2284.      else if(fractype == MPNEWTBASIN)
  2285.         fractype = NEWTBASIN;
  2286.       }
  2287.       else
  2288.       {
  2289.      if(fractype == NEWTON)
  2290.            fractype = MPNEWTON;
  2291.      else if(fractype == NEWTBASIN)
  2292.            fractype = MPNEWTBASIN;
  2293.       }
  2294.       curfractalspecific = &fractalspecific[fractype];
  2295.    }
  2296.  
  2297.    /* set up table of roots of 1 along unit circle */
  2298.    degree = (int)parm.x;
  2299.    if(degree < 2)
  2300.       degree = 3;   /* defaults to 3, but 2 is possible */
  2301.    root = 1;
  2302.  
  2303.    /* precalculated values */
  2304.    roverd    = (double)root / (double)degree;
  2305.    d1overd    = (double)(degree - 1) / (double)degree;
  2306.    maxcolor    = 0;
  2307.    threshold    = .3*PI/degree; /* less than half distance between roots */
  2308.    if (fractype == MPNEWTON || fractype == MPNEWTBASIN) {
  2309.       mproverd       = *pd2MP(roverd);
  2310.       mpd1overd    = *pd2MP(d1overd);
  2311.       mpthreshold  = *pd2MP(threshold);
  2312.       mpone       = *pd2MP(1.0);
  2313.    }
  2314.  
  2315.    floatmin = FLT_MIN;
  2316.    floatmax = FLT_MAX;
  2317.  
  2318.    basin = 0;
  2319.    if(roots != staticroots) {
  2320.       free(roots);
  2321.       roots = staticroots;
  2322.    }
  2323.  
  2324.    if (fractype==NEWTBASIN)
  2325.    {
  2326.       if(parm.y)
  2327.      basin = 2; /*stripes */
  2328.       else
  2329.      basin = 1;
  2330.       if(degree > 16)
  2331.       {
  2332.      if((roots=(CMPLX *)malloc(degree*sizeof(CMPLX)))==NULL)
  2333.      {
  2334.         roots = staticroots;
  2335.         degree = 16;
  2336.      }
  2337.       }
  2338.       else
  2339.      roots = staticroots;
  2340.  
  2341.       /* list of roots to discover where we converged for newtbasin */
  2342.       for(i=0;i<degree;i++)
  2343.       {
  2344.      roots[i].x = cos(i*PI*2.0/(double)degree);
  2345.      roots[i].y = sin(i*PI*2.0/(double)degree);
  2346.       }
  2347.    }
  2348.    else if (fractype==MPNEWTBASIN)
  2349.    {
  2350.      if(parm.y)
  2351.      basin = 2; /*stripes */
  2352.       else
  2353.      basin = 1;
  2354.  
  2355.       if(degree > 16)
  2356.       {
  2357.      if((MPCroots=(struct MPC *)malloc(degree*sizeof(struct MPC)))==NULL)
  2358.      {
  2359.         MPCroots = (struct MPC *)staticroots;
  2360.         degree = 16;
  2361.      }
  2362.       }
  2363.       else
  2364.      MPCroots = (struct MPC *)staticroots;
  2365.  
  2366.       /* list of roots to discover where we converged for newtbasin */
  2367.       for(i=0;i<degree;i++)
  2368.       {
  2369.      MPCroots[i].x = *pd2MP(cos(i*PI*2.0/(double)degree));
  2370.      MPCroots[i].y = *pd2MP(sin(i*PI*2.0/(double)degree));
  2371.       }
  2372.    }
  2373.  
  2374.    if (degree%4 == 0)
  2375.       symmetry = XYAXIS;
  2376.    else
  2377.       symmetry = XAXIS;
  2378.  
  2379.    calctype=StandardFractal;
  2380.    if (fractype == MPNEWTON || fractype == MPNEWTBASIN)
  2381.       setMPfunctions();
  2382.    return(1);
  2383. }
  2384.  
  2385.  
  2386. StandaloneSetup()
  2387. {
  2388.    timer(0,curfractalspecific->calctype);
  2389.    return(0);        /* effectively disable solid-guessing */
  2390. }
  2391.  
  2392. UnitySetup()
  2393. {
  2394.    periodicitycheck = 0;
  2395.    FgOne = (1L << bitshift);
  2396.    FgTwo = FgOne + FgOne;
  2397.    return(1);
  2398. }
  2399.  
  2400. MandelfpSetup()
  2401. {
  2402.    c_exp = param[2];
  2403.    pwr.x = param[2] - 1.0;
  2404.    pwr.y = param[3];
  2405.    floatparm = &init;
  2406.    switch (fractype)
  2407.    {
  2408.    case MANDELFP:
  2409.     /*
  2410.        floating point code could probably be altered to handle many of
  2411.        the situations that otherwise are using StandardFractal().
  2412.        calcmandfp() can currently handle invert, any rqlim, potflag
  2413.        zmag, epsilon cross, and all the current outside options
  2414.                              Wes Loewer 11/03/91
  2415.     */
  2416.     if (debugflag != 90
  2417.         && !distest
  2418.         && decomp[0] == 0
  2419.         && biomorph == -1
  2420.         && (inside >= -1 || inside == -59 || inside == -100)
  2421.         /* uncomment this next line if more outside options are added */
  2422.         /* && outside >= -5 */
  2423.         && useinitorbit != 1)
  2424.     {
  2425.        calctype = calcmandfp; /* the normal case - use calcmandfp */
  2426.        calcmandfpasmstart();
  2427.     }
  2428.     else
  2429.     {
  2430.        /* special case: use the main processing loop */
  2431.        calctype = StandardFractal;
  2432.     }
  2433.     break;
  2434.    case FPMANDELZPOWER:
  2435.       if(c_exp < 1)
  2436.          c_exp = 1;
  2437.       if(c_exp & 1) /* odd exponents */
  2438.          symmetry = XYAXIS_NOPARM;
  2439.       if(param[3] != 0 || (double)c_exp != param[2])
  2440.          symmetry = NOSYM;
  2441.       if(param[4] == 0.0 && debugflag != 6000 && (double)c_exp == param[2])
  2442.           fractalspecific[fractype].orbitcalc = floatZpowerFractal;
  2443.       else
  2444.           fractalspecific[fractype].orbitcalc = floatCmplxZpowerFractal;
  2445.       break;
  2446.    case MAGNET1M:
  2447.    case MAGNET2M:
  2448.       attr[0].x = 1.0;        /* 1.0 + 0.0i always attracts */
  2449.       attr[0].y = 0.0;        /* - both MAGNET1 and MAGNET2 */
  2450.       attractors = 1;
  2451.       break;
  2452.    case SPIDERFP:
  2453.       if(periodicitycheck==1) /* if not user set */
  2454.      periodicitycheck=4;
  2455.       break;
  2456.    case MANDELEXP:
  2457.       symmetry = XAXIS_NOPARM;
  2458.       break;
  2459.    default:
  2460.       break;
  2461.    }
  2462.    return(1);
  2463. }
  2464.  
  2465. JuliafpSetup()
  2466. {
  2467.    c_exp = param[2];
  2468.    floatparm = &parm;
  2469.    if(fractype==COMPLEXMARKSJUL)
  2470.    {
  2471.       pwr.x = param[2] - 1.0;
  2472.       pwr.y = param[3];
  2473.       Coefficient = ComplexPower(*floatparm, pwr);
  2474.    }
  2475.    switch (fractype)
  2476.    {
  2477.    case JULIAFP:
  2478.     /*
  2479.        floating point code could probably be altered to handle many of
  2480.        the situations that otherwise are using StandardFractal().
  2481.        calcmandfp() can currently handle invert, any rqlim, potflag
  2482.        zmag, epsilon cross, and all the current outside options
  2483.                              Wes Loewer 11/03/91
  2484.     */
  2485.     if (debugflag != 90
  2486.         && !distest
  2487.         && decomp[0] == 0
  2488.         && biomorph == -1
  2489.         && (inside >= -1 || inside == -59 || inside == -100)
  2490.         /* uncomment this next line if more outside options are added */
  2491.         /* && outside >= -5 */
  2492.         && useinitorbit != 1
  2493.         && !finattract)
  2494.     {
  2495.        calctype = calcmandfp; /* the normal case - use calcmandfp */
  2496.        calcmandfpasmstart();
  2497.     }
  2498.     else
  2499.     {
  2500.        /* special case: use the main processing loop */
  2501.        calctype = StandardFractal;
  2502.        get_julia_attractor (0.0, 0.0);   /* another attractor? */
  2503.     }
  2504.     break;
  2505.    case FPJULIAZPOWER:
  2506.       if((c_exp & 1) || param[3] != 0.0 || (double)c_exp != param[2] )
  2507.          symmetry = NOSYM;
  2508.       else if(c_exp < 1)
  2509.          c_exp = 1;
  2510.       if(param[4] == 0.0 && debugflag != 6000 && (double)c_exp == param[2])
  2511.           fractalspecific[fractype].orbitcalc = floatZpowerFractal;
  2512.       else
  2513.           fractalspecific[fractype].orbitcalc = floatCmplxZpowerFractal;
  2514.       break;
  2515.    case MAGNET2J:
  2516.       FloatPreCalcMagnet2();
  2517.    case MAGNET1J:
  2518.       attr[0].x = 1.0;        /* 1.0 + 0.0i always attracts */
  2519.       attr[0].y = 0.0;        /* - both MAGNET1 and MAGNET2 */
  2520.       attractors = 1;
  2521.       get_julia_attractor (0.0, 0.0);    /* another attractor? */
  2522.       break;
  2523.    case LAMBDAFP:
  2524.       get_julia_attractor (0.0, 0.0);    /* another attractor? */
  2525.       get_julia_attractor (0.5, 0.0);    /* another attractor? */
  2526.       break;
  2527.    case LAMBDAEXP:
  2528.       if(parm.y == 0.0)
  2529.      symmetry=XAXIS;
  2530.       get_julia_attractor (0.0, 0.0);    /* another attractor? */
  2531.       break;
  2532.    default:
  2533.       get_julia_attractor (0.0, 0.0);    /* another attractor? */
  2534.       break;
  2535.    }
  2536.    return(1);
  2537. }
  2538.  
  2539. MandellongSetup()
  2540. {
  2541.    FgHalf = fudge >> 1;
  2542.    c_exp = param[2];
  2543.    if(fractype==MARKSMANDEL && c_exp < 1)
  2544.       c_exp = 1;
  2545.    if(fractype==LMANDELZPOWER && c_exp < 1)
  2546.       c_exp = 1;
  2547.    if((fractype==MARKSMANDEL   && !(c_exp & 1)) ||
  2548.        (fractype==LMANDELZPOWER && c_exp & 1))
  2549.       symmetry = XYAXIS_NOPARM;    /* odd exponents */
  2550.    if((fractype==MARKSMANDEL && (c_exp & 1)) || fractype==LMANDELEXP)
  2551.       symmetry = XAXIS_NOPARM;
  2552.    if(fractype==SPIDER && periodicitycheck==1)
  2553.       periodicitycheck=4;
  2554.    longparm = &linit;
  2555.    if(fractype==LMANDELZPOWER)
  2556.    {
  2557.       if(param[4] == 0.0 && debugflag != 6000  && (double)c_exp == param[2])
  2558.           fractalspecific[fractype].orbitcalc = longZpowerFractal;
  2559.       else
  2560.           fractalspecific[fractype].orbitcalc = longCmplxZpowerFractal;
  2561.       if(param[3] != 0 || (double)c_exp != param[2] )
  2562.          symmetry = NOSYM;
  2563.     }
  2564.  
  2565.    return(1);
  2566. }
  2567.  
  2568. JulialongSetup()
  2569. {
  2570.    c_exp = param[2];
  2571.    longparm = &lparm;
  2572.    switch (fractype)
  2573.    {
  2574.    case LJULIAZPOWER:
  2575.       if((c_exp & 1) || param[3] != 0.0 || (double)c_exp != param[2])
  2576.          symmetry = NOSYM;
  2577.       else if(c_exp < 1)
  2578.          c_exp = 1;
  2579.       if(param[4] == 0.0 && debugflag != 6000 && (double)c_exp == param[2])
  2580.           fractalspecific[fractype].orbitcalc = longZpowerFractal;
  2581.       else
  2582.           fractalspecific[fractype].orbitcalc = longCmplxZpowerFractal;
  2583.       break;
  2584.    case LAMBDA:
  2585.       get_julia_attractor (0.0, 0.0);    /* another attractor? */
  2586.       get_julia_attractor (0.5, 0.0);    /* another attractor? */
  2587.       break;
  2588.    case LLAMBDAEXP:
  2589.       if(lparm.y == 0)
  2590.      symmetry = XAXIS;
  2591.       break;
  2592.    default:
  2593.       get_julia_attractor (0.0, 0.0);    /* another attractor? */
  2594.       break;
  2595.    }
  2596.    return(1);
  2597. }
  2598.  
  2599. TrigPlusSqrlongSetup()
  2600. {
  2601.    curfractalspecific->per_pixel =  julia_per_pixel;
  2602.    curfractalspecific->orbitcalc =  TrigPlusSqrFractal;
  2603.    if(lparm.x == fudge && lparm.y == 0L && lparm2.y == 0L && debugflag != 90)
  2604.    {
  2605.       if(lparm2.x == fudge)       /* Scott variant */
  2606.      curfractalspecific->orbitcalc =  ScottTrigPlusSqrFractal;
  2607.       else if(lparm2.x == -fudge)  /* Skinner variant */
  2608.      curfractalspecific->orbitcalc =  SkinnerTrigSubSqrFractal;
  2609.    }
  2610.    return(JulialongSetup());
  2611. }
  2612.  
  2613. TrigPlusSqrfpSetup()
  2614. {
  2615.    curfractalspecific->per_pixel =  juliafp_per_pixel;
  2616.    curfractalspecific->orbitcalc =  TrigPlusSqrfpFractal;
  2617.    if(parm.x == 1.0 && parm.y == 0.0 && parm2.y == 0.0 && debugflag != 90)
  2618.    {
  2619.       if(parm2.x == 1.0)    /* Scott variant */
  2620.      curfractalspecific->orbitcalc =  ScottTrigPlusSqrfpFractal;
  2621.       else if(parm2.x == -1.0)    /* Skinner variant */
  2622.      curfractalspecific->orbitcalc =  SkinnerTrigSubSqrfpFractal;
  2623.    }
  2624.    return(JuliafpSetup());
  2625. }
  2626.  
  2627. TrigPlusTriglongSetup()
  2628. {
  2629.    FnPlusFnSym();
  2630.    if(trigndx[1] == SQR)
  2631.       return(TrigPlusSqrlongSetup());
  2632.    curfractalspecific->per_pixel =  long_julia_per_pixel;
  2633.    curfractalspecific->orbitcalc =  TrigPlusTrigFractal;
  2634.    if(lparm.x == fudge && lparm.y == 0L && lparm2.y == 0L && debugflag != 90)
  2635.    {
  2636.       if(lparm2.x == fudge)       /* Scott variant */
  2637.      curfractalspecific->orbitcalc =  ScottTrigPlusTrigFractal;
  2638.       else if(lparm2.x == -fudge)  /* Skinner variant */
  2639.      curfractalspecific->orbitcalc =  SkinnerTrigSubTrigFractal;
  2640.    }
  2641.    return(JulialongSetup());
  2642. }
  2643.  
  2644. TrigPlusTrigfpSetup()
  2645. {
  2646.    FnPlusFnSym();
  2647.    if(trigndx[1] == SQR)
  2648.       return(TrigPlusSqrfpSetup());
  2649.    curfractalspecific->per_pixel =  otherjuliafp_per_pixel;
  2650.    curfractalspecific->orbitcalc =  TrigPlusTrigfpFractal;
  2651.    if(parm.x == 1.0 && parm.y == 0.0 && parm2.y == 0.0 && debugflag != 90)
  2652.    {
  2653.       if(parm2.x == 1.0)    /* Scott variant */
  2654.      curfractalspecific->orbitcalc =  ScottTrigPlusTrigfpFractal;
  2655.       else if(parm2.x == -1.0)    /* Skinner variant */
  2656.      curfractalspecific->orbitcalc =  SkinnerTrigSubTrigfpFractal;
  2657.    }
  2658.    return(JuliafpSetup());
  2659. }
  2660.  
  2661. FnPlusFnSym() /* set symmetry matrix for fn+fn type */
  2662. {
  2663.    static char far fnplusfn[7][7] =
  2664.    {/* fn2 ->sin     cos    sinh    cosh   exp    log    sqr  */
  2665.    /* fn1 */
  2666.    /* sin */ {PI_SYM,XAXIS, XYAXIS, XAXIS, XAXIS, XAXIS, XAXIS},
  2667.    /* cos */ {XAXIS, PI_SYM,XAXIS,  XYAXIS,XAXIS, XAXIS, XAXIS},
  2668.    /* sinh*/ {XYAXIS,XAXIS, XYAXIS, XAXIS, XAXIS, XAXIS, XAXIS},
  2669.    /* cosh*/ {XAXIS, XYAXIS,XAXIS,  XYAXIS,XAXIS, XAXIS, XAXIS},
  2670.    /* exp */ {XAXIS, XYAXIS,XAXIS,  XAXIS, XYAXIS,XAXIS, XAXIS},
  2671.    /* log */ {XAXIS, XAXIS, XAXIS,  XAXIS, XAXIS, XAXIS, XAXIS},
  2672.    /* sqr */ {XAXIS, XAXIS, XAXIS,  XAXIS, XAXIS, XAXIS, XYAXIS}
  2673.    };
  2674.    if(parm.y == 0.0 && parm2.y == 0.0)
  2675.     { if(trigndx[0] < 7 && trigndx[1] < 7)  /* bounds of array JCO 5/6/92*/
  2676.         symmetry = fnplusfn[trigndx[0]][trigndx[1]];  /* JCO 5/6/92 */
  2677.     }                 /* defaults to XAXIS symmetry JCO 5/6/92 */
  2678.    else
  2679.       symmetry = NOSYM;
  2680.    return(0);
  2681. }
  2682.  
  2683. ZXTrigPlusZSetup()
  2684. {
  2685. /*   static char far ZXTrigPlusZSym1[] = */
  2686.    /* fn1 ->  sin   cos    sinh  cosh exp   log   sqr */
  2687. /*         {XAXIS,XYAXIS,XAXIS,XYAXIS,XAXIS,NOSYM,XYAXIS}; */
  2688. /*   static char far ZXTrigPlusZSym2[] = */
  2689.    /* fn1 ->  sin   cos    sinh  cosh exp   log   sqr */
  2690. /*         {NOSYM,ORIGIN,NOSYM,ORIGIN,NOSYM,NOSYM,ORIGIN}; */
  2691.  
  2692.    if(param[1] == 0.0 && param[3] == 0.0)
  2693. /*      symmetry = ZXTrigPlusZSym1[trigndx[0]]; */
  2694.    switch(trigndx[0])
  2695.    {
  2696.       case COS:   /* changed to two case statments and made any added */
  2697.       case COSH:  /* functions default to XAXIS symmetry. JCO 5/25/92 */
  2698.       case SQR:
  2699.       case 9:   /* 'real' cos */
  2700.          symmetry = XYAXIS;
  2701.          break;
  2702.       case LOG:
  2703.          symmetry = NOSYM;
  2704.          break;
  2705.       default:
  2706.          symmetry = XAXIS;
  2707.          break;
  2708.       }
  2709.    else
  2710. /*      symmetry = ZXTrigPlusZSym2[trigndx[0]]; */
  2711.    switch(trigndx[0])
  2712.    {
  2713.       case COS:
  2714.       case COSH:
  2715.       case SQR:
  2716.       case 9:   /* 'real' cos */
  2717.          symmetry = ORIGIN;
  2718.          break;
  2719.       default:
  2720.          symmetry = XAXIS;
  2721.          break;
  2722.       }
  2723.    if(curfractalspecific->isinteger)
  2724.    {
  2725.       curfractalspecific->orbitcalc =  ZXTrigPlusZFractal;
  2726.       if(lparm.x == fudge && lparm.y == 0L && lparm2.y == 0L && debugflag != 90)
  2727.       {
  2728.      if(lparm2.x == fudge)       /* Scott variant */
  2729.          curfractalspecific->orbitcalc =  ScottZXTrigPlusZFractal;
  2730.      else if(lparm2.x == -fudge)  /* Skinner variant */
  2731.          curfractalspecific->orbitcalc =  SkinnerZXTrigSubZFractal;
  2732.       }
  2733.       return(JulialongSetup());
  2734.    }
  2735.    else
  2736.    {
  2737.       curfractalspecific->orbitcalc =  ZXTrigPlusZfpFractal;
  2738.       if(parm.x == 1.0 && parm.y == 0.0 && parm2.y == 0.0 && debugflag != 90)
  2739.       {
  2740.      if(parm2.x == 1.0)    /* Scott variant */
  2741.          curfractalspecific->orbitcalc =  ScottZXTrigPlusZfpFractal;
  2742.      else if(parm2.x == -1.0)    /* Skinner variant */
  2743.          curfractalspecific->orbitcalc =  SkinnerZXTrigSubZfpFractal;
  2744.       }
  2745.    }
  2746.    return(JuliafpSetup());
  2747. }
  2748.  
  2749. LambdaTrigSetup()
  2750. {
  2751.    int isinteger;
  2752.    if((isinteger = curfractalspecific->isinteger))
  2753.       curfractalspecific->orbitcalc =  LambdaTrigFractal;
  2754.    else
  2755.       curfractalspecific->orbitcalc =  LambdaTrigfpFractal;
  2756.    switch(trigndx[0])
  2757.    {
  2758.    case SIN:
  2759.    case COS:
  2760.       symmetry = PI_SYM;
  2761.       if(isinteger)
  2762.      curfractalspecific->orbitcalc =  LambdaTrigFractal1;
  2763.       else
  2764.      curfractalspecific->orbitcalc =  LambdaTrigfpFractal1;
  2765.       break;
  2766.    case SINH:
  2767.    case COSH:
  2768.       symmetry = ORIGIN;
  2769.       if(isinteger)
  2770.      curfractalspecific->orbitcalc =  LambdaTrigFractal2;
  2771.       else
  2772.      curfractalspecific->orbitcalc =  LambdaTrigfpFractal2;
  2773.       break;
  2774.    case SQR:
  2775.       symmetry = ORIGIN;
  2776.       break;
  2777.    case EXP:
  2778.       if(isinteger)
  2779.      curfractalspecific->orbitcalc =  LongLambdaexponentFractal;
  2780.       else
  2781.      curfractalspecific->orbitcalc =  LambdaexponentFractal;
  2782.       symmetry = XAXIS;
  2783.       break;
  2784.    case LOG:
  2785.       symmetry = NOSYM;
  2786.       break;
  2787.    }
  2788.    if(isinteger)
  2789.       return(JulialongSetup());
  2790.    else
  2791.       return(JuliafpSetup());
  2792. }
  2793.  
  2794. JuliafnPlusZsqrdSetup()
  2795. {
  2796. /*   static char far fnpluszsqrd[] = */
  2797.    /* fn1 ->  sin   cos    sinh  cosh    sqr    exp   log  */
  2798.    /* sin    {NOSYM,ORIGIN,NOSYM,ORIGIN,ORIGIN,NOSYM,NOSYM}; */
  2799.  
  2800. /*   symmetry = fnpluszsqrd[trigndx[0]];   JCO  5/8/92 */
  2801.    switch(trigndx[0]) /* fix sqr symmetry & add additional functions */
  2802.    {
  2803.    case COS: /* cosxx */
  2804.    case COSH:
  2805.    case SQR:
  2806.    case 9:   /* 'real' cos */
  2807.    case 10:  /* tan */
  2808.    case 11:  /* tanh */
  2809.    symmetry = ORIGIN;
  2810.     /* default is for NOSYM symmetry */
  2811.    }
  2812.    if(curfractalspecific->isinteger)
  2813.       return(JulialongSetup());
  2814.    else
  2815.       return(JuliafpSetup());
  2816. }
  2817.  
  2818. SqrTrigSetup()
  2819. {
  2820. /*   static char far SqrTrigSym[] = */
  2821.    /* fn1 ->  sin    cos    sinh   cosh   sqr     exp   log  */
  2822. /*         {PI_SYM,PI_SYM,XYAXIS,XYAXIS,XYAXIS,XAXIS,XAXIS}; */
  2823. /*   symmetry = SqrTrigSym[trigndx[0]];      JCO  5/9/92 */
  2824.    switch(trigndx[0]) /* fix sqr symmetry & add additional functions */
  2825.    {
  2826.    case SIN:
  2827.    case COS: /* cosxx */
  2828.    case 9:   /* 'real' cos */
  2829.    symmetry = PI_SYM;
  2830.     /* default is for XAXIS symmetry */
  2831.    }
  2832.    if(curfractalspecific->isinteger)
  2833.       return(JulialongSetup());
  2834.    else
  2835.       return(JuliafpSetup());
  2836. }
  2837.  
  2838. FnXFnSetup()
  2839. {
  2840.    static char far fnxfn[7][7] =
  2841.    {/* fn2 ->sin     cos    sinh    cosh  exp    log    sqr */
  2842.    /* fn1 */
  2843.    /* sin */ {PI_SYM,YAXIS, XYAXIS,XYAXIS,XAXIS, NOSYM, XYAXIS},
  2844.    /* cos */ {YAXIS, PI_SYM,XYAXIS,XYAXIS,XAXIS, NOSYM, XYAXIS},
  2845.    /* sinh*/ {XYAXIS,XYAXIS,XYAXIS,XYAXIS,XAXIS, NOSYM, XYAXIS},
  2846.    /* cosh*/ {XYAXIS,XYAXIS,XYAXIS,XYAXIS,XAXIS, NOSYM, XYAXIS},
  2847.    /* exp */ {XAXIS, XAXIS, XAXIS, XAXIS, XAXIS, NOSYM, XYAXIS},
  2848.    /* log */ {NOSYM, NOSYM, NOSYM, NOSYM, NOSYM, XAXIS, NOSYM},
  2849.    /* sqr */ {XYAXIS,XYAXIS,XYAXIS,XYAXIS,XYAXIS,NOSYM, XYAXIS},
  2850.    };
  2851.    /*
  2852.    if(trigndx[0]==EXP || trigndx[0]==LOG || trigndx[1]==EXP || trigndx[1]==LOG)
  2853.       symmetry = XAXIS;
  2854.    else if((trigndx[0]==SIN && trigndx[1]==SIN)||(trigndx[0]==COS && trigndx[1]==COS))
  2855.       symmetry = PI_SYM;
  2856.    else if((trigndx[0]==SIN && trigndx[1]==COS)||(trigndx[0]==COS && trigndx[1]==SIN))
  2857.       symmetry = YAXIS;
  2858.    else
  2859.       symmetry = XYAXIS;
  2860.    */
  2861.    if(trigndx[0] < 7 && trigndx[1] < 7)  /* bounds of array JCO 5/22/92*/
  2862.         symmetry = fnxfn[trigndx[0]][trigndx[1]];  /* JCO 5/22/92 */
  2863.                     /* defaults to XAXIS symmetry JCO 5/22/92 */
  2864.    else {  /* added to complete the symmetry JCO 5/22/92 */
  2865.       if (trigndx[0]==LOG || trigndx[1] ==LOG) symmetry = NOSYM;
  2866.       if (trigndx[0]==9 || trigndx[1] ==9) { /* 'real' cos */
  2867.          if (trigndx[0]==SIN || trigndx[1] ==SIN) symmetry = PI_SYM;
  2868.          if (trigndx[0]==COS || trigndx[1] ==COS) symmetry = PI_SYM;
  2869.       }
  2870.       if (trigndx[0]==9 && trigndx[1] ==9) symmetry = PI_SYM;
  2871.    }
  2872.    if(curfractalspecific->isinteger)
  2873.       return(JulialongSetup());
  2874.    else
  2875.       return(JuliafpSetup());
  2876. }
  2877.  
  2878. MandelTrigSetup()
  2879. {
  2880.    int isinteger;
  2881.    if((isinteger = curfractalspecific->isinteger))
  2882.       curfractalspecific->orbitcalc =  LambdaTrigFractal;
  2883.    else
  2884.       curfractalspecific->orbitcalc =  LambdaTrigfpFractal;
  2885.    symmetry = XYAXIS_NOPARM;
  2886.    switch(trigndx[0])
  2887.    {
  2888.    case SIN:
  2889.    case COS:
  2890.       if(isinteger)
  2891.      curfractalspecific->orbitcalc =  LambdaTrigFractal1;
  2892.       else
  2893.      curfractalspecific->orbitcalc =  LambdaTrigfpFractal1;
  2894.       break;
  2895.    case SINH:
  2896.    case COSH:
  2897.       if(isinteger)
  2898.      curfractalspecific->orbitcalc =  LambdaTrigFractal2;
  2899.       else
  2900.      curfractalspecific->orbitcalc =  LambdaTrigfpFractal2;
  2901.       break;
  2902.    case EXP:
  2903.       symmetry = XAXIS_NOPARM;
  2904.       if(isinteger)
  2905.      curfractalspecific->orbitcalc =  LongLambdaexponentFractal;
  2906.       else
  2907.      curfractalspecific->orbitcalc =  LambdaexponentFractal;
  2908.       break;
  2909.    case LOG:
  2910.       symmetry = XAXIS_NOPARM;
  2911.       break;
  2912.    }
  2913.    if(isinteger)
  2914.       return(MandellongSetup());
  2915.    else
  2916.       return(MandelfpSetup());
  2917. }
  2918.  
  2919. MarksJuliaSetup()
  2920. {
  2921.    c_exp = param[2];
  2922.    longparm = &lparm;
  2923.    lold = *longparm;
  2924.    if(c_exp > 2)
  2925.       lcpower(&lold,c_exp,&lcoefficient,bitshift);
  2926.    else if(c_exp == 2)
  2927.    {
  2928.       lcoefficient.x = multiply(lold.x,lold.x,bitshift) - multiply(lold.y,lold.y,bitshift);
  2929.       lcoefficient.y = multiply(lold.x,lold.y,bitshiftless1);
  2930.    }
  2931.    else if(c_exp < 2)
  2932.       lcoefficient = lold;
  2933.    return(1);
  2934. }
  2935.  
  2936. SierpinskiSetup()
  2937. {
  2938.    /* sierpinski */
  2939.    periodicitycheck = 0;        /* disable periodicity checks */
  2940.    ltmp.x = 1;
  2941.    ltmp.x = ltmp.x << bitshift; /* ltmp.x = 1 */
  2942.    ltmp.y = ltmp.x >> 1;            /* ltmp.y = .5 */
  2943.    return(1);
  2944. }
  2945.  
  2946. SierpinskiFPSetup()
  2947. {
  2948.    /* sierpinski */
  2949.    periodicitycheck = 0;        /* disable periodicity checks */
  2950.    tmp.x = 1;
  2951.    tmp.y = 0.5;
  2952.    return(1);
  2953. }
  2954.  
  2955.  
  2956. StandardSetup()
  2957. {
  2958.    if(fractype==UNITYFP)
  2959.       periodicitycheck=0;
  2960.    return(1);
  2961. }
  2962.  
  2963. demowalk()
  2964. {
  2965.     extern double param[];        /* optional user parameters */
  2966.     extern int maxit;            /* maximum iterations (steps) */
  2967.     extern int rflag, rseed;        /* random number seed */
  2968.     extern int xdots, ydots;        /* image coordinates */
  2969.     extern int colors;                  /* maximum colors available */
  2970.     extern double far *dx0, far *dy0;    /* arrays of pixel coordinates */
  2971.     extern double far *dx1, far *dy1;    /* (... for skewed zoom-boxes) */
  2972.  
  2973.     float stepsize;            /* average stepsize */
  2974.     int xwalk, ywalk;            /* current position */
  2975.     int xstep, ystep;            /* current step */
  2976.     int steps;                /* number of steps */
  2977.     int color;                /* color to draw this step */
  2978.     float temp, tempadjust;        /* temporary variables */
  2979.  
  2980. if (param[0] != 999) {            /* if 999, do a Mandelbrot instead */
  2981.  
  2982.     srand(rseed);            /* seed the random number generator */
  2983.     if (!rflag) ++rseed;
  2984.     tempadjust = RAND_MAX >> 2;        /* adjustment factor */
  2985.  
  2986.     xwalk = xdots / 2;            /* start in the center of the image */
  2987.     ywalk = ydots / 2;
  2988.  
  2989.     stepsize = min(xdots, ydots)     /* calculate average stepsize */
  2990.                * (param[0]/100.0);    /* as a percentage of the image */
  2991.  
  2992.     color = max(0, min(colors, param[1]));  /* set the initial color */  
  2993.  
  2994.     for (steps = 0; steps < maxit; steps++) { /* take maxit steps */
  2995.         if (keypressed())        /* abort if told to do so */
  2996.             return(0);
  2997.         temp = rand();            /* calculate the next xstep */
  2998.         xstep = ((temp/tempadjust) - 2.0) * stepsize;
  2999.         xstep = min(xwalk + xstep, xdots - 1);
  3000.         xstep = max(0, xstep);
  3001.         temp = rand();            /* calculate the next ystep */
  3002.         ystep = ((temp/tempadjust) - 2.0) * stepsize;
  3003.         ystep = min(ywalk + ystep, ydots - 1);
  3004.         ystep = max(0, ystep);
  3005.         if (param[1] == 0.0)        /* rotate the colors? */
  3006.             if (++color >= colors)    /* rotate the colors, avoiding */
  3007.                 color = 1;        /* the background color 0 */
  3008.         /* the draw_line function is borrowed from the 3D routines */
  3009.         draw_line(xwalk, ywalk,xstep,ystep,color);
  3010.         /* or, we could be on a pogo stick and just displaying
  3011.            where we landed...
  3012.         putcolor(xstep, ystep, color);
  3013.         */
  3014.  
  3015.         xwalk = xstep;            /* remember where we were */
  3016.         ywalk = ystep;
  3017.         }
  3018.     return(1);                          /* we're done */
  3019.  
  3020. } else {                /* a simple Mandelbrot routine */
  3021.  
  3022.     /* the following routine determines the X and Y values of
  3023.        each pixel coordinate and calculates a simple mandelbrot
  3024.        fractal with them - slowly, but surely */
  3025.     int ix, iy;
  3026.     for (iy = 0; iy < ydots; iy++) {
  3027.         for (ix = 0; ix < xdots; ix++) {
  3028.             int iter;
  3029.             double x, y, newx, newy, tempxx, tempxy, tempyy;
  3030.             /* first, obtain the X and Y coordinate values of this pixel */
  3031.             x = dx0[ix]+dx1[iy];
  3032.             y = dy0[iy]+dy1[ix];
  3033.             /* now initialize the temporary values */
  3034.             tempxx = tempyy = tempxy = 0.0;
  3035.             if (keypressed())        /* abort if told to do so */
  3036.                 return(0);
  3037.             /* the inner iteration loop */
  3038.             for (iter = 1; iter < maxit; iter++) {
  3039.                 /* calculate the X and Y values of Z(iter) */
  3040.                 newx = tempxx - tempyy + x;
  3041.                 newy = tempxy + tempxy + y;
  3042.                 /* calculate the temporary values */
  3043.                 tempxx = newx * newx;
  3044.                 tempyy = newy * newy;
  3045.                 tempxy = newx * newy;
  3046.                 /* are we done yet? */
  3047.                 if (tempxx + tempyy > 4.0) break;
  3048.                 }
  3049.             /* color in the pixel */
  3050.             putcolor(ix, iy, iter & (colors - 1));
  3051.             }
  3052.         }
  3053.     return(1);                          /* we're done */
  3054.     }
  3055.  
  3056. }
  3057.